Gomaa Intelligence.Data Hub
عربي

Foundations › Power BI › DAX & Power Query cheat sheet

DAX & Power Query cheat sheet

DAX & Power Query Cheat Sheet

Core DAX functions, CALCULATE patterns, time intelligence and a Power Query M quick reference, with every line runnable.

Basic aggregation

Total Sales = SUM(FactSales[Sales])

Sum of a column in the current context.

Avg Price = AVERAGE(FactSales[UnitPrice])

Average of a column.

Orders = COUNTROWS(FactSales)

Number of table rows.

Customers = DISTINCTCOUNT(FactSales[CustomerID])

Count of distinct values.

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.

Profit = [Total Sales] - [Total Cost]

A measure built from other measures.

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

Status = IF([Margin %] < 0.25, "Low", "OK")

A simple condition.

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?

IF(ISBLANK([Total Sales]), 0, [Total Sales])

Turn blank into zero.

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.

YoY % = DIVIDE([Total Sales] - [Sales LY], [Sales LY])

Year-over-year growth.

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

VALUES(DimProduct[Category])

Distinct values visible in the current context.

DISTINCT(DimCustomer[City])

Distinct values of a column.

FILTER(DimProduct, DimProduct[ListPrice] > 2000)

A table of rows that meet the condition.

ALL(DimProduct)

All rows of the table, unfiltered.

COUNTROWS(VALUES(DimProduct[Product]))

Number of products visible in context.

{ "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 data

Open Power Query Editor.

Modeling ▸ New measure

Create a new measure and write DAX.

Model view ▸ اسحب المفتاح على المفتاح

Create a relationship by dragging key to key.

Alt + Enter  /  Shift + Enter

New line inside the formula bar.

View ▸ Performance analyzer

Measure every visual's time and tune performance.

Home ▸ Refresh

Refresh 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.

Request an analytics service ↗
Get your data analyzed by an expert ↗