Power BI Course · DAX and modeling lesson
DAX and Data Modeling: Relationships, Measures and Context
Learn star-schema relationships, row and filter context, SUMX versus SUM and a checkable percent-of-total measure.
Learn the design method, inspect a worked scenario, and test a fresh variation.
Core idea
The same measure changes because the filter context changes.
All = 65
North = 35
The direct answer
Separate row calculation from filter context.
DAX measures are evaluated in the current filter context of the report. A region slicer changes which fact rows contribute to a measure through model relationships. Iterators such as SUMX evaluate an expression per row before aggregation. Understanding those two ideas is more useful than memorising a measure that happens to work on one visual.
This lesson uses three sales rows and two customers to compare SUMX with SUM, then calculate a region share with an explicit denominator. The examples are original and arithmetically checkable. Course pricing follows this introduction.
Course access
Choose your next step in Power BI.
Review the current course options and access details here.
Heycademy Courses · Coming Soon
Master Power BI with Heycademy
We’re preparing an interactive learning experience with practical exercises, skill assessments and personalized learning to help you build confidence and master new skills.
We’re putting the finishing touches on this course. Please check back for updates.
Model before DAX
One Customer row can filter many Sales rows.
| CustomerID | Region |
|---|---|
| C1 | North |
| C2 | South |
| Sale | CustomerID | Quantity | UnitPrice |
|---|---|---|---|
| S1 | C1 | 2 | 10 |
| S2 | C1 | 1 | 15 |
| S3 | C2 | 3 | 10 |
CustomerID is unique in Customer and repeats in Sales. An active one-to-many relationship allows Customer[Region] to filter Sales. If the dimension has duplicate C1 keys, the model’s assumed cardinality fails. Microsoft’s star-schema guidance explains why dimension keys and fact grain matter.
Worked measure
Multiply each row, then add the results.
Sales Amount = SUMX(Sales, Sales[Quantity] * Sales[UnitPrice])| Filter | Included line amounts | Sales Amount |
|---|---|---|
| All | 20 + 15 + 30 | 65 |
| North | 20 + 15 | 35 |
| South | 30 | 30 |
SUMX is appropriate because the desired expression is quantity times price on each row. SUM(Sales[UnitPrice]) adds 10 + 15 + 10 = 35, which is not revenue. If Power Query or a calculated column had already created a correct numeric LineAmount column, SUM(Sales[LineAmount]) could also return 65. The choice is about what is stored and what the metric means.
Row and filter context
Two different questions inside the same measure.
Inside SUMX, the expression is evaluated for each Sales row: S1 gives 20, S2 gives 15 and S3 gives 30. The report’s filter context determines which of those rows the measure sees. A North slicer filters Customer to C1; the active relationship propagates that filter to S1 and S2; the measure then sums 20 and 15.
CALCULATE can evaluate an expression under a modified filter context. This is useful for a denominator that should ignore the Region filter while retaining other intended filters, such as a selected month. The exact set of filters to remove is a business decision. Read Microsoft’s CALCULATE documentation before changing context in a complex model.
Keep building this skill
Turn the example into a checked report.
Return to the course options whenever you are ready.
Common wrong method
A denominator that keeps Region returns 100%.
Suppose you write Region Share = DIVIDE([Sales Amount], [Sales Amount]). In a North row, numerator and denominator both see North and are both 35, so the result is 100%. The formula is syntactically valid but answers the wrong question. A report total of 100% can look plausible while each region row is wrong.
| Region | Wrong same-context ratio | Correct all-region share |
|---|---|---|
| North | 35 / 35 = 100% | 35 / 65 ≈ 53.85% |
| South | 30 / 30 = 100% | 30 / 65 ≈ 46.15% |
Do not fix the display by formatting 100% differently. Define the denominator, modify the appropriate filter and recompute from source rows.
Fresh variation
What if South gains another sale?
Add S4 for C2, quantity 2 at unit price 20. The new line is 40; all sales are 105; North remains 35; South becomes 70. North share is 35 ÷ 105 = 33.33%, and South share is 66.67% under no other filters.
Show the reasoning
The model relationship routes S4 to South. SUMX adds 40 to the all-region total and South. Removing Region for the denominator gives 105 in both region rows. If North sales changes, inspect the relationship or filters.
For a separate Power Query view of source typing, see the cleaning lesson. DAX cannot make a malformed imported quantity trustworthy.
A second context check
A month filter should usually remain in the share.
Suppose S1 is in January and S2/S3 are in February. February sales are North 15 and South 30, total 45. If the report asks for each region’s share of February sales, North should be 15/45 = 33.33% and South 30/45 = 66.67%. A denominator that removes all filters, including Month, would use 65 and answer a different question.
| Context | North numerator | Intended denominator | North share |
|---|---|---|---|
| All dates | 35 | 65 | 53.85% |
| February only | 15 | 45 | 33.33% |
This is why REMOVEFILTERS(Customer[Region]) is deliberately narrower than removing filters from the entire model. It lets the selected month continue to filter Sales through Calendar. Test two months and at least two regions. If a report has additional customer-level filters, decide explicitly whether those belong in the denominator.
For a fresh challenge, add a February sale of 10 to North. February North becomes 25, February total 55, and North share becomes 25/55 ≈ 45.45%. The numerator and denominator both change, but for different reasons. State those reasons before modifying DAX.
FAQ
Questions about this skill.
Is SUMX always better than SUM?
No. SUM adds one existing numeric column; SUMX evaluates an expression for each row. Choose according to the metric and model.
Why does a slicer change a measure?
It changes filter context, which can propagate through active relationships to the fact rows.
Why is my percent of total 100% for every region?
The denominator may be evaluated under the same Region filter as the numerator. Define and test the intended denominator.
Continue with the course
Build reliable Power BI skills.
Review the course options and choose your next learning step.