
π This article includes 3 downloadable practice files β
In this article
List Value = SUMX ( Sales, Sales[Qty] * RELATED ( Products[Price] ) )
Discount Rs =
VAR ListValue = [List Value]
VAR Sold = SUM ( Sales[Amount] )
RETURN ListValue - Sold
Discount % = DIVIDE ( [Discount Rs], [List Value] )
Practice model: 700 orders, 275 sold below list price, βΉ8,42,138 discount in total (2.91%).
Why variables
- Readable: each step has a name.
- Faster: a variable is calculated once, even if used three times.
- Debuggable: temporarily
RETURN ListValueto see an intermediate value in a card. - Correct context: a variable is evaluated where it’s defined, which is how “growth vs last year” keeps the current value fixed.
DIVIDE, not /
DIVIDE(a, b) returns blank when b is 0 or blank, so a region with no sales last year shows an empty cell instead of an error or infinity. Add a third argument for a different fallback: DIVIDE(a, b, 0).
Practice
Import pbi-intermediate-model.xlsx into Power BI Desktop (free), create the relationships listed at the top of the .dax file, mark the Date table as a date table and add this lesson’s measures. Compare your card and table values with the lesson’s sheet in the expected-results file. Those numbers were worked out independently in Python from the same data, so a mismatch means a filter or relationship to check.
π Practice files for this article
β¬ Download all 3 files (ZIP Β· 61 KB)
- πPractice model (Excel)Two years of sales (700 orders, FY 2024-25 and 2025-26) with Customers, Products, a full Date table, Targets and RegionUsers.β¬ XLSX Β· 63 KB
- πLesson 5 measures (.dax)Every measure from this lesson, ready to paste into Power BI Desktop.β¬ DAX Β· 999 B
- πExpected resultsThe numbers your measures should show, one sheet per lesson.β¬ XLSX Β· 11 KB
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.