Step 2: Build Query Programs
Create Infactory Intelligent Queries using natural language
Build Query Programs
Transform your business questions into Infactory Intelligent Queries. Infactory’s AI understands natural language and helps you create powerful analytics tailored to your data.
Infactory Intelligent Queries are reusable analytics that can be deployed as APIs. Think of them as smart functions that understand your data.
Your First Query Program
Let’s start with a fundamental business question that every advertiser needs to answer.

Create Your First Query
After your data source is connected:
- Look for the “Build” section in the left sidebar
- Click the ”+” button next to “Build”
- A new “Untitled query” appears in the Build section
- The main area shows “Use the assistant to build a query”

Use the AI Assistant
Now let’s use Infactory’s AI Assistant to create your query:
- Click the “Assistant” button on the right side
- A text box appears with “Use our AI Assistant to ask questions about your data”
- Type your question in natural language
Type a natural language question about your data. For example:
- “What’s the ROAS for each campaign?”
- “What’s the CPC for each campaign id?”
- “How does CTR correlate with conversion performance?”
Press Enter or click the send button.

Infactory’s AI understands your business context. Start with simple questions, then build more complex analytics as needed.
Review the Generated Query
Infactory’s AI Assistant generates a complete query program and displays it in the code editor:

Generated query program code in the editor
You’ll see:
- The complete query program code
- Clear variable definitions
- Comments explaining the logic
- Calculations based on your specific question
You can review and modify the code if needed. Infactory generates well-structured, readable code.
Test Your Query
Now run the query to see actual results:
- Click the “Run” button at the bottom right
- Results appear below the code editor with two view options:

Query results with Pretty and Raw view tabs
Pretty tab: A formatted table and chart visualization (default)
- Automatic chart visualization for quick insights
- Detailed data table below the chart
- Column headers and rows match your query
- Sortable columns, copy, and download options
Raw tab: The complete JSON response with metadata
- Complete API response in JSON format
- Includes metadata, execution trace, and timing information
- Useful for debugging or integrating with other systems
Success! Your query has executed and returned results. The data is now ready for analysis or deployment as an API.
Automatic Save: When you run a query successfully, Infactory automatically:
- Generates a descriptive name based on your query
- Saves the query program to your Build section
You’ll see the query name change from “Untitled query” to something meaningful like “Campaign ROAS Analysis” or similar.
Pro Tips for Query Creation
Be Specific
Include exact metric names and calculation methods
Add Context
Explain why you need the query for better results
Test First
Always test before saving to ensure accuracy
Iterate Quickly
Refine queries based on test results
Query Management
After creating your queries, you’ll see them in your Query Library:

Your query library with all created programs
Features available:
- 📝 Edit queries anytime
- 🔄 Clone and modify existing queries
- 📊 View usage statistics
Common Issues & Solutions
Query returns no results
Query returns no results
- Check column names match exactly
- Verify filters aren’t too restrictive
- Ensure data exists for your criteria
Calculations seem wrong
Calculations seem wrong
- Verify the formula logic in the query program
- Check for null values affecting calculations
- Test with known values to validate
Query takes too long
Query takes too long
- Add filters to reduce data volume
- Avoid complex nested calculations
- Contact support for optimization help
Ready to Deploy?
You’ve built a powerful suite of analytics queries. Now let’s turn them into production APIs!
Continue to Deploy APIs
Transform your queries into live endpoints →
Progress Update: You’re about 4 minutes in and have created intelligent analytics that would typically take days to build. Next, we’ll deploy them as APIs!