BS Consulting
Blog

DAX filter context: Why one formula gives three answers

A matrix shows each line’s contribution to the plant’s rejects. Every row says 100 percent. The arithmetic is fine. The numerator and denominator see exactly the same rows.

Which filters reach the cell?

Assume a star schema with plant, calendar and Line dimensions filtering the production fact. The report selects North plant and June. Matrix row A adds a filter on Line[LineCode]. A measure sums only the facts satisfying all those conditions. At the grand total the matrix evaluates a fresh context without the individual line row.

Rejected units in the selected plant and month
LineRejectsPlant denominatorShare
A122060%
B62030%
C22010%
Contributions to the plant’s 20 rejects
A60%
B30%
C10%

Remove one filter deliberately

Create the following expressions as separate measures. The first counts rejected units. In the second, the numerator uses the current context. CALCULATE evaluates the same measure in the denominator after REMOVEFILTERS clears the restriction on the LineCode column. Plant and month continue to apply. For line A, the numerator is 12 and the denominator is 20.

DAX
Rejects = SUM(Production[Rejected])

// Separate measure
Share of Plant Rejects =
DIVIDE(
    [Rejects],
    CALCULATE([Rejects], REMOVEFILTERS(Line[LineCode]))
)

Why only one column? Suppose the Line dimension also contains LineType. A slicer on type may need to remain effective if the report promises shares within that type. A separate filter on LineName also remains effective. The example assumes the matrix actually uses LineCode. Match the field used by the visual and the filters removed by the measure to the intended comparison group.

Choose which population the reader should see

If a LineCode slicer shows only A and B, the formula still removes that slicer’s restriction from the denominator. The visible rows contribute 60 and 30 percent respectively. This is appropriate for a title such as “Share of whole plant”. If the selected lines are themselves the population, the denominator should be 18. That produces about 66.7 and 33.3 percent. An ALLSELECTED-based calculation may suit that request. Test it on the actual matrix.

These shares also answer a different question from the reject rate. A high-volume line can contribute many rejects while performing well per inspected part. Display the numerator and denominator beside the percentage when the comparison might otherwise be ambiguous.

Build the selected-lines comparison

For the alternative question about shares within the selected lines, place this extra measure beside the first. In this simple matrix ALLSELECTED on LineCode removes the individual row subdivision while respecting the outer selection. The example uses a slicer and a matrix on that same column without additional iterators or nested visual calculations.

DAX
Share of Selected Lines =
DIVIDE(
    [Rejects],
    CALCULATE([Rejects], ALLSELECTED(Line[LineCode]))
)

Run two checks. When A and B are selected, the new measure should show about 66.7 percent for A and 100 percent for the total. In the same selection, the original measure should give 18 out of 20, or 90 percent, at the grand total. Comparing them on the same page makes each denominator explicit.

Try it yourself

Another plant has 80 rejects in June. After a model change line A shows 12 percent. Which filter is likely missing from the denominator?

Show the solution

Twelve percent corresponds to 12 out of 100. The denominator apparently covers both plants. Temporarily show it as a separate measure. It must be 20 in North. Check the plant relationship and whether the formula removes more filters than intended.

Sources and further reading