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.

POWER BI LESSON PREVIEW
DAX and modeling lessonDesign → test

Core idea

The same measure changes because the filter context changes.

SUMX(rows, qty × price)
All = 65
North = 35
Check the model and result.Compare each result with the source rows and filter context.

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.

Launching soon!
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.

Customer dimension
CustomerIDRegion
C1North
C2South
Sales fact
SaleCustomerIDQuantityUnitPrice
S1C1210
S2C1115
S3C2310

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])
Expected measure values
FilterIncluded line amountsSales Amount
All20 + 15 + 3065
North20 + 1535
South3030

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.

Explore course options →

Percent of total

Name the denominator before writing DAX.

For a region share of all-region sales under the current non-region filters, the expected North share is 35 ÷ 65 ≈ 53.85%; South is 30 ÷ 65 ≈ 46.15%. A measure can remove only the Region filter for the denominator:

Region Share =
DIVIDE(
    [Sales Amount],
    CALCULATE([Sales Amount], REMOVEFILTERS(Customer[Region]))
)

This assumes Region is the only Customer attribute whose filter you intend to clear. If a CustomerID slicer remains, the denominator may still be customer-restricted. If the business means all customers regardless of any Customer filter, the measure needs a different filter-removal scope. Test under at least two slicer states before accepting the output. Microsoft documents REMOVEFILTERS as a filter-clearing function.

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.

Bad versus corrected calculation
RegionWrong same-context ratioCorrect all-region share
North35 / 35 = 100%35 / 65 ≈ 53.85%
South30 / 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.

Region-share behavior under date context
ContextNorth numeratorIntended denominatorNorth share
All dates356553.85%
February only154533.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.

Take the next step →
Scroll to Top