Calculate a total for each entity, then average those totals to measure the average contribution per entity. This pattern is useful for metrics such as average revenue per customer or average volume per location, where the desired average is over entity totals rather than individual rows.
Compare average store revenue across regions by totaling revenue for each store, then averaging those totals. Each store with sales in the selected data contributes equally to the average.
Source data: The sales dataset contains one row per sale, with revenue , store_id , and region columns. store_id uniquely identifies a store. Each store can have multiple sales rows.
Formula : AVG(GROUPINEX(SUM(revenue), [store_id], []))
Total revenue: The inner SUM(revenue) adds revenue across sales rows.
Calculate one total per store: GROUPINEX(..., [store_id], []) adds store to the chart's grouping dimensions. The empty third argument excludes no dimensions.
Average the totals: The outer AVG(...) averages those totals within each chart group. Each store represented in the selected data contributes one total, regardless of its number of sales rows.
Example result: Store totals of 200 and 600 give average store revenue of 400 , even if the stores have different numbers of sales rows.
Measure: In a column chart grouped by region, shows average revenue for stores with sales in each region.
Having filter: Keep regions with average store revenue above 400 using formula > 400 .
npm install @luzmo/nodejs-sdk{
"count": 1,
"rows": [
{
"created_at": "2024-05-20T12:44:23.163Z",
"currency_id": null,
"description": {
"en": "Average revenue total across stores represented in the selected data"
},
"ai_context": null,
"expression": "AVG(GROUPINEX(SUM({<sales_dataset_id>:<revenue_column_id>}), [{<sales_dataset_id>:<store_id_column_id>}], []))",
"format": ",.2af",
"id": "a5ad615a-5199-4e58-8e0e-73dceba18af0",
"informat": "numeric",
"lowestLevel": 0,
"name": {
"en": "Average store revenue"
},
"subtype": null,
"type": "numeric",
"updated_at": "2024-05-20T13:29:37.273Z",
"custom_metadata": null,
"user_id": "34b22f36-4904-497f-8acf-b0ba1d7e83cb"
}
]
}