Menu
CoddyTech

Power BI Cheat Sheet

Last updated

Learn Power BI free

Measures, columns and tables

A measure is computed for each cell of a visual; a calculated column is computed once per row and stored.

What it doesDAX
Create a measureTotal Sales = SUM ( Sales[Amount] )
Create a calculated column (one value per row)Line Total = Sales[Quantity] * Sales[Unit Price]
Create a calculated tableTop Customers = TOPN ( 10, Customer, [Total Sales] )
Refer to a column: table name, then the column in bracketsSales[Amount]
Quote a table name that has a space or is a reserved word'Date'[Date]
Refer to a measure: brackets only[Total Sales]
Use a measure inside another measureAverage Price = DIVIDE ( [Total Sales], [Total Units] )

Aggregation functions

Each one summarizes a column in the current filter context.

What it doesDAX
Add up a columnSUM ( Sales[Amount] )
Average of a columnAVERAGE ( Sales[Amount] )
Smallest valueMIN ( Sales[Order Date] )
Largest valueMAX ( Sales[Order Date] )
Count the rows of a tableCOUNTROWS ( Sales )
Count the non blank values of a columnCOUNT ( Sales[Amount] )
Count distinct valuesDISTINCTCOUNT ( Sales[Customer Key] )
Divide safely: blank instead of an error when the bottom is 0DIVIDE ( [Total Sales], [Total Units] )
Divide with a value to show when the bottom is 0DIVIDE ( [Profit], [Total Sales], 0 )

Iterators (the X functions)

They go through a table row by row, evaluate an expression for each row, then aggregate the results.

What it doesDAX
Multiply per row, then add upSUMX ( Sales, Sales[Quantity] * Sales[Unit Price] )
Average of a per row resultAVERAGEX ( Sales, Sales[Quantity] * Sales[Unit Price] )
Largest per row resultMAXX ( Sales, Sales[Quantity] * Sales[Unit Price] )
Average of a measure per customerAVERAGEX ( VALUES ( Customer[Customer Key] ), [Total Sales] )
Use a column of a related table in the expressionSUMX ( Sales, Sales[Quantity] * RELATED ( Product[Unit Cost] ) )
Count the rows that pass a testCOUNTROWS ( FILTER ( Sales, Sales[Quantity] >= 3 ) )
Rank every product by a measureRANKX ( ALL ( Product[Product] ), [Total Sales] )
Rank with no gaps after ties (1, 1, 2)RANKX ( ALL ( Product[Product] ), [Total Sales], , DESC, DENSE )
Join values into one textCONCATENATEX ( VALUES ( Product[Category] ), Product[Category], ", " )

CALCULATE and filter functions

CALCULATE evaluates an expression with changed filters. Filters on the same column replace the old one; filters on different columns combine with AND.

What it doesDAX
Filter on one valueCALCULATE ( [Total Sales], Product[Category] = "Bikes" )
Filter on a list of valuesCALCULATE ( [Total Sales], Product[Color] IN { "Red", "Blue" } )
Two filters (AND)CALCULATE ( [Total Sales], Product[Color] = "Red", Store[Country] = "Spain" )
OR across two columnsCALCULATE ( [Total Sales], FILTER ( ALL ( Product[Color], Product[Brand] ), Product[Color] = "Red" || Product[Brand] = "Contoso" ) )
Filter by a measureCALCULATE ( [Total Sales], FILTER ( VALUES ( Customer[Customer Key] ), [Total Sales] > 1000 ) )
Keep the existing filter and intersect with itCALCULATE ( [Total Sales], KEEPFILTERS ( Product[Color] IN { "Red", "Blue" } ) )
Remove the filters on a columnCALCULATE ( [Total Sales], REMOVEFILTERS ( Product[Category] ) )
Remove every filter on a tableCALCULATE ( [Total Sales], ALL ( Product ) )
Remove all filters on a table except some columnsCALCULATE ( [Total Sales], ALLEXCEPT ( Store, Store[Country] ) )
Keep the slicer selection, drop the visual's own rowsCALCULATE ( [Total Sales], ALLSELECTED ( Product[Category] ) )
Use an inactive relationshipCALCULATE ( [Total Sales], USERELATIONSHIP ( Sales[Ship Date], 'Date'[Date] ) )
Let a filter flow both ways for one measureCALCULATE ( COUNTROWS ( Customer ), CROSSFILTER ( Sales[Customer Key], Customer[Customer Key], BOTH ) )
Filter by a table with no relationshipCALCULATE ( [Total Sales], TREATAS ( VALUES ( Budget[Category] ), Product[Category] ) )

Time intelligence

These need a date table: one row per day, no gaps, marked as a date table.

What it doesDAX
Year to dateTOTALYTD ( [Total Sales], 'Date'[Date] )
Year to date, fiscal year ending 30 JuneTOTALYTD ( [Total Sales], 'Date'[Date], "6/30" )
Year to date inside CALCULATECALCULATE ( [Total Sales], DATESYTD ( 'Date'[Date] ) )
Quarter to dateTOTALQTD ( [Total Sales], 'Date'[Date] )
Month to dateTOTALMTD ( [Total Sales], 'Date'[Date] )
Same period last yearCALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
Shift the dates by an interval (here one month back)CALCULATE ( [Total Sales], DATEADD ( 'Date'[Date], -1, MONTH ) )
The whole previous monthCALCULATE ( [Total Sales], PREVIOUSMONTH ( 'Date'[Date] ) )
The whole period one year backCALCULATE ( [Total Sales], PARALLELPERIOD ( 'Date'[Date], -1, YEAR ) )
The last 12 months up to the last visible dateCALCULATE ( [Total Sales], DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -12, MONTH ) )
A fixed date rangeCALCULATE ( [Total Sales], DATESBETWEEN ( 'Date'[Date], DATE ( 2025, 1, 1 ), DATE ( 2025, 3, 31 ) ) )

Common measure patterns

Copy, then rename the tables and columns to match your model.

What it doesDAX
Percent of all categoriesCategory % = DIVIDE ( [Total Sales], CALCULATE ( [Total Sales], REMOVEFILTERS ( Product[Category] ) ) )
Percent of what the slicers leaveVisible % = DIVIDE ( [Total Sales], CALCULATE ( [Total Sales], ALLSELECTED ( Product[Category] ) ) )
Year over year growthYoY % = VAR LastYear = CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) ) RETURN DIVIDE ( [Total Sales] - LastYear, LastYear )
Running total over all timeRunning Total = CALCULATE ( [Total Sales], FILTER ( ALL ( 'Date'[Date] ), 'Date'[Date] <= MAX ( 'Date'[Date] ) ) )
7 day moving average (per day with sales)Sales 7 Day Avg = AVERAGEX ( DATESINPERIOD ( 'Date'[Date], MAX ( 'Date'[Date] ), -7, DAY ), [Total Sales] )
Show a value only for the top 5Top 5 Sales = IF ( RANKX ( ALLSELECTED ( Product[Product] ), [Total Sales] ) <= 5, [Total Sales] )
Count customers above a thresholdBig Customers = COUNTROWS ( FILTER ( VALUES ( Customer[Customer Key] ), [Total Sales] > 1000 ) )
Make a total add up its rowsBonus Total = SUMX ( VALUES ( Product[Category] ), [Bonus] )
Show a value only at one level of a matrixCategory Rank = IF ( ISINSCOPE ( Product[Category] ), RANKX ( ALL ( Product[Category] ), [Total Sales] ) )
Closing balance: the last date that has a valueClosing Units = CALCULATE ( SUM ( Inventory[Units] ), LASTNONBLANK ( 'Date'[Date], CALCULATE ( SUM ( Inventory[Units] ) ) ) )

Logical and information functions

For conditions, and for asking what the filter context holds.

What it doesDAX
One conditionIF ( [Total Sales] > 1000, "High", "Low" )
Several values of one expressionSWITCH ( Store[Country], "Spain", "ES", "Portugal", "PT", "Other" )
Ranges, checked top to bottomSWITCH ( TRUE (), [Total Sales] >= 10000, "A", [Total Sales] >= 1000, "B", "C" )
AND and ORIF ( Sales[Quantity] > 2 && Sales[Amount] > 50, "Big", "Small" )
Is the value blank?ISBLANK ( [Total Sales] )
First value that is not blankCOALESCE ( [Total Sales], 0 )
Does the filter leave exactly one value?HASONEVALUE ( Product[Category] )
That one value, or a defaultSELECTEDVALUE ( Product[Category], "All categories" )
Is this row of the visual grouped by the column?ISINSCOPE ( Product[Category] )
Return a blankBLANK ()

Text functions

The & operator joins text; FORMAT turns a number or date into text.

What it doesDAX
Join textCustomer[First Name] & " " & Customer[Last Name]
Format a numberFORMAT ( [Total Sales], "#,0.00" )
Format a dateFORMAT ( 'Date'[Date], "mmm yyyy" )
First charactersLEFT ( Product[Code], 3 )
Characters from a positionMID ( Product[Code], 4, 2 )
LengthLEN ( Product[Name] )
Upper caseUPPER ( Store[City] )
Remove extra spacesTRIM ( Customer[Name] )
Replace textSUBSTITUTE ( Customer[Phone], " ", "" )
Position of a text, ignoring case (0 when missing)SEARCH ( "pro", Product[Name], 1, 0 )

Date functions

Dates are numbers underneath, so you can subtract them to get days.

What it doesDAX
Today's dateTODAY ()
Build a dateDATE ( 2025, 12, 31 )
Year of a dateYEAR ( 'Date'[Date] )
Month numberMONTH ( 'Date'[Date] )
Weekday, Monday as 1WEEKDAY ( 'Date'[Date], 2 )
Week number, weeks starting MondayWEEKNUM ( 'Date'[Date], 2 )
Last day of the monthEOMONTH ( 'Date'[Date], 0 )
Same day one month earlierEDATE ( 'Date'[Date], -1 )
Days between two datesDATEDIFF ( Sales[Order Date], Sales[Ship Date], DAY )
A date table from fixed datesCALENDAR ( DATE ( 2024, 1, 1 ), DATE ( 2025, 12, 31 ) )
A date table from the dates in the modelCALENDARAUTO ()

Relationships and lookups

RELATED follows a relationship from the many side to the one side.

What it doesDAX
Value from the one side (in a column on Sales)RELATED ( Product[Category] )
The many side rows of the current row (in a column on Customer)COUNTROWS ( RELATEDTABLE ( Sales ) )
Look up a value with no relationshipLOOKUPVALUE ( Product[Price], Product[SKU], Sales[SKU] )
Parent child path (for hierarchies and row-level security)PATH ( Employee[Employee ID], Employee[Manager ID] )
The signed in user, for dynamic row-level securityUSERPRINCIPALNAME ()

Table functions

They return tables: use them in a calculated table, inside CALCULATE, or in an iterator.

What it doesDAX
Distinct values in the current filterVALUES ( Product[Category] )
Rows that pass a testFILTER ( Product, Product[Price] > 100 )
The top N rows by a measureTOPN ( 5, ALL ( Product[Product] ), [Total Sales] )
Group by columns and add measuresSUMMARIZECOLUMNS ( Product[Category], "Sales", [Total Sales] )
Add a column to a tableADDCOLUMNS ( VALUES ( Product[Category] ), "Sales", [Total Sales] )
Pick and rename columnsSELECTCOLUMNS ( Customer, "Name", Customer[Name], "City", Customer[City] )
A list of numbersGENERATESERIES ( 1, 10, 1 )
Every combination of two tablesCROSSJOIN ( VALUES ( 'Date'[Year] ), VALUES ( Product[Category] ) )
Stack two tables with the same columnsUNION ( 'Sales 2024', 'Sales 2025' )

Variables

VAR names a step and computes it once; RETURN gives the result.

What it doesDAX
One variableMargin % = VAR Revenue = [Total Sales] RETURN DIVIDE ( Revenue - [Total Cost], Revenue )
Several variablesSales vs LY = VAR CY = [Total Sales] VAR PY = CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) ) RETURN CY - PY
A table in a variableTop 5 Total = VAR Top5 = TOPN ( 5, ALL ( Product[Product] ), [Total Sales] ) RETURN CALCULATE ( [Total Sales], Top5 )

Power Query (M) steps

Power Query shapes data before it loads. These are the M formulas behind the common buttons.

What it doesM
Keep the rows that matchTable.SelectRows(Source, each [Status] = "Paid")
Remove columnsTable.RemoveColumns(Source, {"Notes", "Temp"})
Set column typesTable.TransformColumnTypes(Source, {{"Amount", type number}, {"Date", type date}})
Rename a columnTable.RenameColumns(Source, {{"amt", "Amount"}})
Add a columnTable.AddColumn(Source, "Total", each [Quantity] * [Price], type number)
Merge (join) two queriesTable.NestedJoin(Sales, {"ProductID"}, Products, {"ProductID"}, "Product", JoinKind.LeftOuter)
Append (stack) queriesTable.Combine({Sales2024, Sales2025})
Unpivot columns into rowsTable.UnpivotOtherColumns(Source, {"Product"}, "Month", "Amount")
Group and aggregateTable.Group(Source, {"Category"}, {{"Sales", each List.Sum([Amount]), type number}})
Replace errors with a valueTable.ReplaceErrorValues(Source, {{"Amount", 0}})

This Power BI cheat sheet lists the DAX you write most often, on one page: aggregations, the X iterators, CALCULATE and the functions that change filters, time intelligence, text and date functions, and measure patterns you can copy, such as percent of total, year over year growth and running totals.

The examples use a sales model with Sales, Product, Customer and a 'Date' table; rename them to match yours. The DAX was parsed by the engine behind Coddy's Power BI course, where you can write it in a Power BI workspace in your browser and have it checked.

Power BI cheat sheet FAQ

Is this Power BI cheat sheet free?

Yes. Read it here or bookmark it; there is no sign up.

What is the difference between a measure and a calculated column?

A calculated column is computed once per row at refresh and stored, so you can slice by it. A measure is computed for each cell of a visual, in that cell's filters, and stores nothing. Totals and ratios belong in measures.

What does CALCULATE do?

It evaluates an expression with changed filters: it adds, replaces or removes filters, then computes the result. Most DAX beyond simple totals is CALCULATE with the right filter arguments.

Why use DIVIDE instead of the / operator?
DIVIDE returns a blank (or a value you choose) when the bottom is zero or blank. The / operator returns infinity or an error value instead, which shows up in visuals.
Do I need a date table for time intelligence?
Yes. Functions such as TOTALYTD and SAMEPERIODLASTYEAR need a table with one row per day, no gaps and whole years, related to your facts and marked as a date table.
Does this DAX work in Excel Power Pivot and Analysis Services?

The DAX language is shared, so almost all of it works there too. A few newer functions arrive in Power BI first.

Where can I practise DAX?

In Coddy's Power BI course: each lesson gives you a Power BI workspace in the browser and checks your measure against the lesson's data and hidden copies of it.

Coddy programming languages illustration

Learn Power BI with Coddy

Get started