Aggregate and analyse
Total sales by customer city
Section titled “Total sales by customer city”WHICH Sales Order has WHICH Sold To Customer City AND WHICH Line TotalRETURN SalesOrder.SldToCustCity, SalesOrder.SlsLineTotal.SUMGROUP BY SalesOrder.SldToCustCityThe relationship readings identify the relevant sales concepts. RETURN requests a city and the sum of line totals. GROUP BY creates a group for each city.
Sold To Customer City is a model label, while SalesOrder.SldToCustCity is an explicit field reference from this example model. Your own field names may differ.
Filter before aggregating
Section titled “Filter before aggregating”WHICH Sales Order was on (Sales Date.MONTH:'10')AND was on (Sales Date.YEAR:'2000')RETURN SalesOrder.SldToCustRegion, SalesOrder.SlsLineTotal.SUMGROUP BY SalesOrder.SldToCustRegionThis restricts the source orders to October 2000 before calculating totals by region.
Filter grouped totals
Section titled “Filter grouped totals”The repository README also gives this pattern:
WHICH Sales Order was on (Sales Date.YEAR:'2020')AND has WHICH SldToCustCntry AND WHICH Line TotalRETURN SalesOrder.SldToCustCntry, SalesOrder.SlsLineTotal.SUMGROUP BY SalesOrder.SldToCustCntryHAVING SalesOrder.SlsLineTotal.SUM > 1000000HAVING restricts the grouped results to totals above one million. ORDER BY sorts results; LIMIT bounds the result count. Confirm support for the requested combination in your FactEngine version and target database.
Check what is being counted
Section titled “Check what is being counted”Before using an aggregate, establish what each matching row represents. A sales line count and an order count need not be the same. Relationship paths can also affect multiplicity. Validate analytical queries against known data, including duplicates and empty groups.