Power BI (DAX) cheat sheet
DAX is the formula language for measures and calculated columns in Power BI, Analysis Services, and Power Pivot. It is not the same as Power Query M, which is the separate language used to shape and load data before it reaches the model. Everything below is DAX. Most surprises in DAX come from filter context and context transition, so read the CALCULATE and time-intelligence notes carefully — that is usually where a measure quietly returns the wrong total.
Aggregations
The plain functions aggregate one column. The X variants iterate a table row by row, evaluating an expression per row before aggregating.
SUM(Sales[Amount])SUMX(Sales, Sales[Qty] * Sales[Price])AVERAGE(Sales[Amount])AVERAGEX(Sales, Sales[Qty] * Sales[Price])MAX(Sales[Amount])MAXX(Sales, Sales[Qty] * Sales[Price])COUNT(Sales[OrderID])COUNTA(Sales[Notes])COUNTROWS(Sales)DISTINCTCOUNT(Sales[CustomerID])COUNTBLANK(Sales[Notes])Filter context
CALCULATE is the engine of DAX. It evaluates an expression after changing the filter context, and it forces context transition — turning the current row into an equivalent filter. Almost every non-trivial measure goes through it.
CALCULATE(SUM(Sales[Amount]), Sales[Region] = "West")CALCULATETABLE(Sales, Sales[Year] = 2026)FILTER(Sales, Sales[Amount] > 1000)CALCULATE(SUM(Sales[Amount]), ALL(Sales))CALCULATE(SUM(Sales[Amount]), ALLEXCEPT(Sales, Sales[Region]))CALCULATE(SUM(Sales[Amount]), ALLSELECTED(Sales[Region]))CALCULATE(SUM(Sales[Amount]), REMOVEFILTERS(Sales[Region]))CALCULATE([Sales], KEEPFILTERS(Sales[Region] = "West"))VALUES(Sales[Region])SELECTEDVALUE(Sales[Region], "All regions")HASONEVALUE(Sales[Region])ISFILTERED(Sales[Region])ISINSCOPE(Sales[Region])Iterators & variables
VAR Total = SUM(Sales[Amount]) RETURN Total * 1.1RANKX(ALL(Product), [Total Sales])CONCATENATEX(VALUES(Product[Name]), Product[Name], ", ")ADDCOLUMNS(VALUES(Region[Name]), "Sales", [Total Sales])SELECTCOLUMNS(Sales, "Region", Sales[Region])SUMMARIZE(Sales, Region[Name], "Sales", SUM(Sales[Amount]))SUMMARIZECOLUMNS(Region[Name], "Sales", SUM(Sales[Amount]))Time intelligence
These need a dedicated date table that is contiguous (no gaps), covers full years, and is marked as a date table. Without one, they silently return wrong or blank results.
TOTALYTD(SUM(Sales[Amount]), 'Date'[Date])CALCULATE(SUM(Sales[Amount]), DATESYTD('Date'[Date]))CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR('Date'[Date]))CALCULATE(SUM(Sales[Amount]), DATEADD('Date'[Date], -1, MONTH))CALCULATE(SUM(Sales[Amount]), DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -3, MONTH))CALCULATE(SUM(Sales[Amount]), PARALLELPERIOD('Date'[Date], -1, YEAR))CALCULATE(SUM(Sales[Amount]), PREVIOUSMONTH('Date'[Date]))CALCULATE(SUM(Sales[Amount]), DATESBETWEEN('Date'[Date], DATE(2026,1,1), DATE(2026,3,31)))LASTDATE('Date'[Date])ENDOFMONTH('Date'[Date])Logical & error handling
IF([Sales] > 0, "Yes", "No")SWITCH([Grade], "A", 4, "B", 3, 0)SWITCH(TRUE(), [Margin] > 0.3, "High", [Margin] > 0.1, "Mid", "Low")[Active] && [Approved][IsAdmin] || [IsOwner]NOT(ISBLANK([Sales]))DIVIDE([Profit], [Sales], 0)COALESCE([Sales], 0)IFERROR([Ratio], 0)ISBLANK([Sales])IF([Sales] = 0, BLANK(), [Sales])Relationships
RELATED(Product[Category])COUNTROWS(RELATEDTABLE(Sales))CALCULATE([Sales], USERELATIONSHIP(Sales[ShipDate], 'Date'[Date]))CALCULATE([Sales], CROSSFILTER(Sales[CustID], Customer[CustID], BOTH))LOOKUPVALUE(Rate[USD], Rate[Date], Sales[Date])CALCULATE([Sales], TREATAS(VALUES(Budget[Region]), Sales[Region]))Text
FORMAT([Sales], "#,##0.00")"Region: " & SELECTEDVALUE(Region[Name])LEFT([Code], 3)MID([Code], 4, 2)LEN([Code])UPPER([Code])TRIM([Name])SUBSTITUTE([Code], "-", "")SEARCH("@", [Email], 1, BLANK())VALUE([CodeText])Math & statistics
ROUND([Sales], 2)ROUNDUP([Sales], 0)INT([Value])ABS([Variance])MOD([Row], 2)CEILING([Price], 0.05)MEDIAN(Sales[Amount])PERCENTILE.INC(Sales[Amount], 0.9)RANK.EQ([Sales], ALL(Sales[Amount]))Tables & set operations
These return tables. Use them as the table argument of an iterator or filter, or inside CALCULATETABLE — you cannot put a table directly in a card visual.
TOPN(5, Product, [Total Sales], DESC)UNION(Actuals, Budget)INTERSECT(VALUES(A[ID]), VALUES(B[ID]))EXCEPT(VALUES(A[ID]), VALUES(B[ID]))DISTINCT(Sales[Region])GENERATESERIES(1, 12, 1)ROW("Total", SUM(Sales[Amount]))Security & context info
Used mainly in row-level security (RLS) rules.
Customer[Email] = USERPRINCIPALNAME()USERNAME()CUSTOMDATA()