Measures
Total Sales = SUM(Sales[SalesAmount])By Imonikhe Ayeni
This practical DAX reference starts with measures and context, then moves through CALCULATE, iterators, filter modifiers, relationships, time intelligence, rankings, virtual tables, performance and quality assurance.
DAX is the analytical expression language used in Power BI semantic models, Power Pivot and related tabular technologies.
Total Sales = SUM(Sales[SalesAmount])Line Value = Sales[Quantity] * Sales[UnitPrice]Learn table/column notation, operators, comments and measure naming.
Sales[SalesAmount]
[Total Sales]Growth % =
VAR CurrentValue = [Sales]
VAR PriorValue = [Sales PY]
RETURN DIVIDE(CurrentValue - PriorValue, PriorValue)Context is the central idea in DAX and explains why the same expression can return different values in different visuals.
Exists naturally in calculated columns and iterators such as SUMX.Comes from slicers, filters, rows/columns in visuals and DAX expressions.CALCULATE evaluates an expression after modifying filter context.
Blue Sales = CALCULATE([Total Sales], Product[Colour] = "Blue")All Region Sales = CALCULATE([Total Sales], REMOVEFILTERS(Region))Use SUM, AVERAGE, MIN, MAX, COUNTROWS and DISTINCTCOUNT for common measures.
Transactions = COUNTROWS(Sales)Customers = DISTINCTCOUNT(Sales[CustomerID])Functions ending in X evaluate an expression for each row of a table and then aggregate the results.
Revenue = SUMX(Sales, Sales[Quantity] * Sales[UnitPrice])Avg Customer Sales = AVERAGEX(VALUES(Customer[CustomerID]), [Total Sales])Create table filters and control how existing filters behave.
Large Sales = CALCULATE([Total Sales], FILTER(Sales, Sales[SalesAmount] > 1000))Premium Sales = CALCULATE([Total Sales], KEEPFILTERS(Product[Tier] = "Premium"))Use model relationships first; use DAX relationship functions when the calculation genuinely requires them.
Category = RELATED(Product[Category])Shipped Sales = CALCULATE([Total Sales], USERELATIONSHIP(Sales[ShipDate], 'Date'[Date]))Compare periods using a proper date table and a well-designed model.
Sales PY = CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))Sales YTD = TOTALYTD([Total Sales], 'Date'[Date])Build ratios with DIVIDE and control denominator context intentionally.
Margin % = DIVIDE([Profit], [Total Sales])Share % = DIVIDE([Total Sales], CALCULATE([Total Sales], REMOVEFILTERS(Product[Category])))Rank entities dynamically and build focused views.
Region Rank = RANKX(ALL(Region[Region]), [Total Sales], , DESC, DENSE)Combine ranking measures with visual filters or dedicated Top N measures.Build temporary tables inside measures to solve advanced analytical problems.
Visible Customers = COUNTROWS(VALUES(Customer[CustomerID]))Useful for constructing intermediate grouped tables; use carefully and test semantics.Understand how CALCULATE converts row context into filter context.
Context transition commonly appears when measures are evaluated inside iterators or calculated columns.Inspect the table being iterated, the current filters and whether CALCULATE changes them.Build calculations from tested patterns instead of writing each measure from scratch.
Sales = SUM(Sales[SalesAmount])
Sales PY = ...
YoY % = DIVIDE([Sales] - [Sales PY], [Sales PY])Title = "Sales — " & SELECTEDVALUE(Region[Region], "All Regions")Write calculations that are correct first, then make them efficient and maintainable.
Variables reduce repetition and make intermediate logic easier to inspect.Poor relationships or high-cardinality models cannot be fixed by clever DAX alone.Move from syntax to analytical problem solving.
Create sales, prior-period, variance, share-of-total, ranking and rolling metrics.Build a reusable KPI framework with dynamic targets, context-aware labels and drill-through calculations.Use this section as a quick revision page before an interview or when a term comes up at work. The aim is to understand the idea well enough to explain it in plain language before memorising syntax.
Row context means 'which row am I on?'. Filter context means 'which rows are currently visible to this calculation?'. They are different concepts and can exist at the same time.
CALCULATE evaluates an expression after changing filter context. It can add, replace or remove filters and can trigger context transition.
SUM adds values from one column. SUMX iterates a table, evaluates an expression for each row, and then sums the results.
Use a measure for dynamic report calculations. Use a calculated column for row-level values that must be stored in the model.
It is the conversion of an existing row context into filter context when CALCULATE is evaluated.
DIVIDE handles zero or blank denominators safely and makes the intended fallback behaviour explicit.
These short tasks test whether you can apply the tool, explain your reasoning and validate the result. In a live exercise, say your assumptions aloud and check the output rather than rushing straight to syntax.
Answer: Use an explicit measure with SUM.
Total Sales =
SUM(Sales[SalesAmount])Answer: Divide current-context sales by sales calculated after removing only the category filter.
Why: Removing only the intended filter is safer than clearing more context than necessary.
Category Share % =
DIVIDE(
[Total Sales],
CALCULATE(
[Total Sales],
REMOVEFILTERS(Product[Category])
)
)Answer: Each row creates a different filter context, so the measure is recalculated for that context.
Why: This is one of the most important DAX concepts to explain clearly.
Answer: Use SUM for one existing numeric column. Use SUMX when an expression must be evaluated row by row and then summed.
Revenue =
SUMX(
Sales,
Sales[Quantity] * Sales[UnitPrice]
)Answer: CALCULATE evaluates an expression after changing filter context.
Why: You can then add that it can add, replace or remove filters and can perform context transition.