DAX measures for sales in Power BI
Last updated · SANTOSPANHOL, S.L.
A DAX measure is a formula that calculates a number (sales, margin, variance) according to the report filters; you write it once and it works in any visual. These eight cover a complete sales report.
The eight measures
Assumes a model with F_Sales (Amount, Cost) and a marked date table D_Date.
Sales = SUM(F_Sales[Amount])
Cost = SUM(F_Sales[Cost])
Margin = [Sales] - [Cost]
Margin % = DIVIDE([Margin], [Sales])
Rows = COUNTROWS(F_Sales)
Sales YTD = TOTALYTD([Sales], D_Date[Date])
Sales PY = CALCULATE([Sales], SAMEPERIODLASTYEAR(D_Date[Date]))
Var % PY = DIVIDE([Sales] - [Sales PY], [Sales PY])Why this way
DIVIDEreturns blank instead of an error when the divisor is zero.- Measures build on each other: change
Salesand everything else follows. TOTALYTDandSAMEPERIODLASTYEARneed the marked date table.
Where to keep them
In a measures table or in the fact table, with a display folder and a format (currency, percentage). Name measures the way you would say them in a meeting: "Sales", "Margin %".
Excel to Power BI writes these measures with the names of your amount and cost columns. Try it with your Excel.
FAQ
What is the difference between a measure and a calculated column?
A column is calculated row by row on load and takes memory; a measure is calculated on the fly from the filters and takes no space in the model.
Why use DIVIDE instead of the slash?
DIVIDE handles division by zero and returns blank; the slash returns an error or infinity.
What does TOTALYTD do?
It accumulates a measure from 1 January up to the current date in context, within each year.
Related guides
- Date table in Power BI: create and mark it with DAX
- Star schema in Power BI: what it is and how to build one
- How to go from Excel to Power BI in 5 minutes
Your Excel, turned into a Power BI report. Free preview; download for 49,99 EUR (VAT included).