Foundations › Power BI › DAX & Power Query cheat sheet
DAX & Power Query cheat sheetDAX & Power Query Cheat Sheet
Core DAX functions, CALCULATE patterns, time intelligence and a Power Query M quick reference, with every line runnable.
Basic aggregation
Largest Order = MAX(FactSales[Sales])Largest value in a column (MIN for the smallest).
Margin % = DIVIDE([Profit],[Total Sales])Safe division: returns blank instead of an error on zero.
CALCULATE and filters
Online Sales = CALCULATE([Total Sales], DimChannel[Channel] = "Online")Change the filter context and re-evaluate.
CALCULATE([Total Sales], DimDate[Year] IN {2024, 2025})Several values of one column with IN.
CALCULATE([Total Sales], DimProduct[Category] = "Home", DimChannel[Channel] = "Store")Two filters: both must hold (AND).
CALCULATE([Total Sales], FILTER(FactSales, FactSales[Sales] > 20000))A row-level condition with FILTER.
CALCULATE([Total Sales], REMOVEFILTERS(DimCustomer[City]))Remove the filter of one column.
CALCULATE([Total Sales], REMOVEFILTERS(DimProduct))Remove all filters of a table.
CALCULATE([Total Sales], ALL(DimProduct[Category]))ALL removes the filter and returns every value (acts as a modifier inside CALCULATE).
CALCULATE([Total Sales], ALLEXCEPT(DimProduct, DimProduct[Category]))Remove every filter of the table except the listed columns.
% of All = DIVIDE([Total Sales], CALCULATE([Total Sales], REMOVEFILTERS()))Share of total: with no arguments it removes every filter.
Iterators
Gross Profit = SUMX(FactSales, FactSales[Quantity] * (FactSales[UnitPrice] - FactSales[UnitCost]))Walks every row, calculates, then sums.
Avg Line = AVERAGEX(FactSales, FactSales[Quantity] * FactSales[UnitPrice])A row-by-row average.
Best Product = MAXX(VALUES(DimProduct[Product]), [Total Sales])Highest value across a set (here, products).
Active Products = COUNTROWS(FILTER(VALUES(DimProduct[Product]), [Total Sales] > 0))Count products that have sales.
Category = RELATED(DimProduct[Category])In a row context: fetch a value from the related dimension.
Logic and variables
Band = SWITCH(TRUE(), [Margin %] < 0.2, "Low", [Margin %] < 0.3, "Mid", "High")Many conditions instead of nested IFs.
VAR cur = [Total Sales]
VAR ly = CALCULATE([Total Sales], SAMEPERIODLASTYEAR(DimDate[Date]))
RETURN DIVIDE(cur - ly, ly)VAR names intermediate results and improves readability.
City = SELECTEDVALUE(DimCustomer[City], "Multiple Cities")The selected value if single, otherwise the fallback.
IF(ISFILTERED(DimCustomer[City]), "Filtered", "All cities")Is the column filtered?
IFERROR([Total Sales] / [Total Cost], 0)A fallback on error (DIVIDE is usually better).
Dates and time intelligence
Sales YTD = TOTALYTD([Total Sales], DimDate[Date])Year-to-date up to the latest date in context.
Sales LY = CALCULATE([Total Sales], SAMEPERIODLASTYEAR(DimDate[Date]))Same period last year.
Sales PM = CALCULATE([Total Sales], DATEADD(DimDate[Date], -1, MONTH))Shift the period back one month.
Sales 2025 = CALCULATE([Total Sales], DimDate[Year] = 2025)A fixed year with a plain filter.
Year = YEAR(DimDate[Date]) // عمود محسوبExtract the year from a date (better as ready-made DimDate columns).
لازم جدول تواريخ مستقل ومتصل بجدول الحقائقEvery time-intelligence function needs a complete Date Table and a sound relationship.
Table functions
FILTER(DimProduct, DimProduct[ListPrice] > 2000)A table of rows that meet the condition.
{ "Online", "Store" }A literal table of values you type (used with IN).
Power Query (M) quick reference
Table.TransformColumnTypes(Source, {{"Sales", type number}})Change a column type (the Changed Type step).
Table.TransformColumns(Source, {{"City", Text.Trim}, {"City", Text.Proper}})Clean text: Trim and Proper.
Table.Distinct(Source)Remove duplicate rows.
Table.SelectRows(Source, each [Amount] > 0)Filter rows.
Table.Group(Source, {"Product"}, {{"Total", each List.Sum([Amount]), type number}})Group By with a sum.
Table.UnpivotOtherColumns(Source, {"Product"}, "Month", "Units")Unpivot to turn wide columns into rows.
Table.NestedJoin(Orders, {"ProductID"}, Products, {"ProductID"}, "P", JoinKind.LeftOuter)Merge Queries (Left Outer).
Table.Combine({Jan, Feb, Mar})Append Queries: stack similar tables.
Shortcuts and ribbon tips
Home ▸ Transform dataOpen Power Query Editor.
Modeling ▸ New measureCreate a new measure and write DAX.
Model view ▸ اسحب المفتاح على المفتاحCreate a relationship by dragging key to key.
Alt + Enter / Shift + EnterNew line inside the formula bar.
View ▸ Performance analyzerMeasure every visual's time and tune performance.
Home ▸ RefreshRefresh data from the source.
Need a real Power BI dashboard for your business?
I design a data model and an executive dashboard fitted to your business and your real data.