πHow to Use This DAX Cheat Sheet
DAX (Data Analysis Expressions) is the formula language of Power BI, Analysis Services and Power Pivot. This cheat sheet groups the DAX functions you will actually use at work and in interviews, each with a short example built on a typical sales model: a Sales fact table, Product, Customer, Store and a marked Date table.
Two ideas explain almost every DAX result:
New to Power BI? Start with the Power BI tutorial for beginners, then come back here.
π1. Aggregation Functions
Total Sales = SUM ( Sales[SalesAmount] )Avg Price = AVERAGE ( Sales[UnitPrice] )Min Order Date = MIN ( Sales[OrderDate] )Max Order Date = MAX ( Sales[OrderDate] )Order Lines = COUNTROWS ( Sales )Orders = DISTINCTCOUNT ( Sales[OrderID] )Non Blank Email = COUNTA ( Customer[Email] )COUNTROWS counts rows of a table and is usually faster and clearer than COUNT on a column. DISTINCTCOUNT is the standard way to count customers or orders.
π2. Iterators (the X Functions)
Iterators walk a table row by row, evaluate an expression, then aggregate.
Revenue = SUMX ( Sales, Sales[Quantity] * Sales[UnitPrice] )Avg Line Value = AVERAGEX ( Sales, Sales[Quantity] * Sales[UnitPrice] )Max Order = MAXX ( VALUES ( Sales[OrderID] ), [Total Sales] )Product List = CONCATENATEX ( VALUES ( Product[Product] ), Product[Product], ", " )Use SUMX when you must multiply or combine columns per row. Use SUM when one column is enough.
π3. CALCULATE and Filter Functions
CALCULATE evaluates an expression in a modified filter context. It is the most important function in DAX.
Sales South = CALCULATE ( [Total Sales], Store[Region] = "South" )Sales All Region = CALCULATE ( [Total Sales], REMOVEFILTERS ( Store[Region] ) )Sales All = CALCULATE ( [Total Sales], ALL ( Sales ) )Sales Keep Cat = CALCULATE ( [Total Sales], ALLEXCEPT ( Product, Product[Category] ) )Big Orders Sales = CALCULATE ( [Total Sales], FILTER ( Sales, Sales[Quantity] > 10 ) )Red Only Keep = CALCULATE ( [Total Sales], KEEPFILTERS ( Product[Color] = "Red" ) )Selected Region = SELECTEDVALUE ( Store[Region], "All regions" )π4. Time Intelligence Functions
These need a continuous date table marked as a date table.
Sales YTD = TOTALYTD ( [Total Sales], 'Date'[Date] )Sales QTD = TOTALQTD ( [Total Sales], 'Date'[Date] )Sales MTD = TOTALMTD ( [Total Sales], 'Date'[Date] )Sales FYTD = TOTALYTD ( [Total Sales], 'Date'[Date], "31/03" )Sales LY = CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )Sales LM = CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, MONTH ) )Sales PY Full = CALCULATE ( [Total Sales], PREVIOUSYEAR ( 'Date'[Date] ) )Sales Last 30D = CALCULATE ( [Total Sales], DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -30, DAY ) )The "31/03" argument in TOTALYTD sets an April to March financial year, which most Indian companies use.
π5. Relationship Functions
Category (col) = RELATED ( Product[Category] )Order Count (col)= COUNTROWS ( RELATEDTABLE ( Sales ) )Sales by Ship = CALCULATE ( [Total Sales], USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] ) )Sales Both Ways = CALCULATE ( [Total Sales], CROSSFILTER ( Sales[CustomerID], Customer[CustomerID], BOTH ) )π6. Logical and Information Functions
Margin Band = SWITCH ( TRUE (), [Margin %] >= 0.4, "High", [Margin %] >= 0.2, "Medium", "Low" )Status = IF ( [Total Sales] > [Target], "On track", "Behind" )Safe Ratio = DIVIDE ( [Profit], [Total Sales], 0 )Has Sales = NOT ISBLANK ( [Total Sales] )Fallback = COALESCE ( [Total Sales], 0 )SWITCH(TRUE(), ...) replaces nested IFs and reads far better. DIVIDE handles divide by zero. COALESCE returns the first non blank value.
π7. Text Functions
Full Name = Customer[FirstName] & " " & Customer[LastName]Initial = LEFT ( Customer[FirstName], 1 )Clean City = UPPER ( TRIM ( Customer[City] ) )Month Text = FORMAT ( 'Date'[Date], "MMM YYYY" )Code = SUBSTITUTE ( Product[SKU], "-", "" )Title = "Sales for " & SELECTEDVALUE ( Store[Region], "all regions" )π8. Ranking and Top N
Product Rank = RANKX ( ALL ( Product[Product] ), [Total Sales], , DESC, DENSE )Top 5 Products Sales =CALCULATE ( [Total Sales], TOPN ( 5, ALL ( Product[Product] ), [Total Sales], DESC ) )Newer DAX also offers RANK, ROWNUMBER and window functions such as OFFSET, INDEX and WINDOW, which make "previous row" and moving calculations easier on visual level data.
π9. Variables
Variables make DAX faster (each is evaluated once) and much easier to debug.
Sales YoY % =VAR CurrentSales = [Total Sales]VAR PriorSales = [Sales LY]RETURN DIVIDE ( CurrentSales - PriorSales, PriorSales )Tip: while debugging, temporarily RETURN one of the variables to check its value.
π10. Table Functions You Will Meet
πReady to Copy DAX Patterns
Percentage of total
% of Total = DIVIDE ( [Total Sales], CALCULATE ( [Total Sales], ALLSELECTED ( Product[Category] ) ) )Running total
Running Total =CALCULATE ( [Total Sales], FILTER ( ALLSELECTED ( 'Date'[Date] ), 'Date'[Date] <= MAX ( 'Date'[Date] ) ) )Three month moving average
Sales 3M Avg =AVERAGEX ( DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -3, MONTH ), [Total Sales] )For a monthly visual, iterate months rather than days for a true monthly average.
New customers
New Customers =VAR MinDate = MIN ( 'Date'[Date] )RETURNCOUNTROWS ( FILTER ( VALUES ( Sales[CustomerID] ), CALCULATE ( MIN ( Sales[OrderDate] ), REMOVEFILTERS ( 'Date' ) ) >= MinDate ) )Dynamic RLS rule
[Email] = USERPRINCIPALNAME ()Applied on a security table related to the fact table, this shows each signed in user only their rows.
πDAX Best Practices
πFrequently Asked Questions
What is the difference between a measure and a calculated column?
A calculated column is computed per row at refresh and stored, using memory. A measure is computed at query time in the current filter context. Use measures for KPIs.What is context transition?
When CALCULATE runs inside a row context, it converts the current row into an equivalent filter context. That is why a measure used inside SUMX or a calculated column gives per row results.Is DAX the same as Excel formulas?
The syntax looks similar and many function names match, but DAX works on tables and columns with filter context, not on cells.How many DAX functions should I know for interviews?
Know aggregations, the X iterators, CALCULATE with ALL, REMOVEFILTERS and FILTER, the main time intelligence functions, RELATED and USERELATIONSHIP, RANKX and variables well. Practise with our Power BI interview questions.Is DAX tested in PL-300?
Yes, under modelling the data: measures, CALCULATE, time intelligence and quick measures. See the PL-300 guide.πLearn It Live
DAX clicks fastest when someone corrects your measures in real time. Prakalpana's Power BI course is taught live online with an optional 1-on-1 track, covering filter context, CALCULATE, time intelligence, performance tuning and real business models. See the full Power BI learning path, then WhatsApp or call +91 9180377502 for a free demo.