Creating Reports
Learn how to build powerful reports, dashboards, and data visualizations in Stack9. This guide covers report types, query building, aggregations, parameters, exports, scheduling, and interactive dashboards.
What You'll Learn
- ✅ Report types (tabular, charts, dashboards)
- ✅ Building report queries with aggregations
- ✅ Report parameters and filters
- ✅ Exporting reports (PDF, Excel, CSV)
- ✅ Scheduling automated reports
- ✅ Creating interactive dashboards
- ✅ Visualization options and best practices
Time Required: 45-60 minutes
Prerequisites
- Completed Custom Queries guide
- Understanding of Entity Relationships
- Entities with data in your Stack9 instance
Understanding Reports in Stack9
Reports in Stack9 are specialized screens that present data in meaningful ways:
- Tabular Reports - Data grids with summaries and totals
- Chart Reports - Visual representations (bar, line, pie charts)
- Dashboard Reports - Multiple visualizations on one screen
- Scheduled Reports - Automated report generation and delivery
Report Types
1. Tabular Reports
Display data in table format with grouping, sorting, and totals.
Use cases: Sales reports, inventory lists, transaction histories
2. Chart Reports
Visualize data with charts and graphs.
Use cases: Revenue trends, sales by region, product performance
3. Dashboard Reports
Combine multiple reports and visualizations.
Use cases: Executive dashboards, KPI tracking, real-time monitoring
4. Scheduled Reports
Automatically generate and email reports on a schedule.
Use cases: Daily sales summaries, weekly inventory reports, monthly financials
Building Your First Report
Let's build a Sales Summary Report that shows revenue by product category.
Step 1: Create the Report Query
Reports start with queries that aggregate and summarize data.
File: src/query-library/getsalessummary.json
{
"key": "getsalessummary",
"name": "getSalesSummary",
"connector": "stack9_api",
"queryTemplate": {
"method": "post",
"path": "/sales_order/search",
"bodyParams": "{\n \"$select\": [\n \"category_id\",\n \"category.name as category_name\",\n \"COUNT(*) as order_count\",\n \"SUM(total_amount) as total_revenue\",\n \"AVG(total_amount) as avg_order_value\"\n ],\n \"$where\": {\n \"_is_deleted\": false,\n \"status\": \"Completed\",\n \"order_date\": {\n \"$gte\": \"{{startDate}}\",\n \"$lte\": \"{{endDate}}\"\n }\n },\n \"$groupBy\": [\"category_id\", \"category.name\"],\n \"$orderBy\": [\n {\"column\": \"total_revenue\", \"order\": \"desc\"}\n ],\n \"$withRelated\": [\"category(notDeleted)\"]\n}",
"queryParams": {}
},
"userParams": {
"startDate": "",
"endDate": ""
}
}
Key Features:
COUNT(*)- Count ordersSUM(total_amount)- Total revenueAVG(total_amount)- Average order value$groupBy- Group by category- Parameters for date range filtering
Step 2: Create the Report Screen
File: src/screens/sales_summary_report.json
{
"head": {
"title": "Sales Summary Report",
"key": "sales_summary_report",
"route": "sales-summary-report",
"app": "reports",
"icon": "BarChartOutlined",
"description": "Revenue summary by product category"
},
"screenType": "listView",
"listQuery": "getsalessummary",
"reportMode": true,
"columnsConfiguration": [
{
"field": "category_name",
"label": "Category",
"value": "{{category_name}}",
"renderAs": "Text"
},
{
"field": "order_count",
"label": "Orders",
"value": "{{order_count}}",
"renderAs": "Number",
"options": {
"format": "0,0"
}
},
{
"field": "total_revenue",
"label": "Total Revenue",
"value": "{{total_revenue}}",
"renderAs": "Currency",
"options": {
"currency": "USD",
"decimals": 2
}
},
{
"field": "avg_order_value",
"label": "Avg Order Value",
"value": "{{avg_order_value}}",
"renderAs": "Currency",
"options": {
"currency": "USD",
"decimals": 2
}
}
],
"filters": [
{
"field": "startDate",
"label": "Start Date",
"type": "date",
"required": true
},
{
"field": "endDate",
"label": "End Date",
"type": "date",
"required": true
}
],
"actions": [
{
"key": "export_pdf",
"label": "Export PDF",
"type": "export",
"format": "pdf"
},
{
"key": "export_excel",
"label": "Export Excel",
"type": "export",
"format": "xlsx"
},
{
"key": "export_csv",
"label": "Export CSV",
"type": "export",
"format": "csv"
}
],
"totals": {
"enabled": true,
"columns": [
{
"field": "order_count",
"type": "sum"
},
{
"field": "total_revenue",
"type": "sum"
},
{
"field": "avg_order_value",
"type": "avg"
}
]
}
}
Key Features:
reportMode: true- Enables report-specific features- Date range filters
- Export actions (PDF, Excel, CSV)
- Column totals
Aggregation Functions
Stack9 supports SQL aggregation functions in queries:
COUNT - Count Records
{
"$select": [
"status",
"COUNT(*) as total_count"
],
"$groupBy": ["status"]
}
SUM - Total Values
{
"$select": [
"product_id",
"SUM(quantity) as total_quantity",
"SUM(line_total) as total_sales"
],
"$groupBy": ["product_id"]
}
AVG - Average Values
{
"$select": [
"category_id",
"AVG(price) as avg_price",
"AVG(rating) as avg_rating"
],
"$groupBy": ["category_id"]
}
MIN/MAX - Minimum/Maximum
{
"$select": [
"product_id",
"MIN(price) as lowest_price",
"MAX(price) as highest_price"
],
"$groupBy": ["product_id"]
}
Multiple Aggregations
{
"$select": [
"sales_rep_id",
"sales_rep.name",
"COUNT(*) as order_count",
"SUM(total_amount) as total_sales",
"AVG(total_amount) as avg_order_value",
"MIN(order_date) as first_order",
"MAX(order_date) as last_order"
],
"$groupBy": ["sales_rep_id", "sales_rep.name"]
}