I would like to calculate total by category. The category is in the dimension table.
Here is sample file: DAX ALLEXCEPT total by category.pbix
I have the f
This is expected behaviour.
Power BI tables will include every row for which any measure in the table does not evaluate to BLANK()
.
ALLEXCEPT
stops the values in the id
and size
columns from affecting the filter context when [Sales]
is computed, and so every possible value for these two columns will give the same (non-blank) result (this causes the cartesian product that you see).
For example, on the (a, black, big) row, the filter context for the measures contains:
FactTable[id] = {"a"}
dim1[color] = {"black"}
dim2[size] = {"big"}
Then CALCULATE([Sales], ALLEXCEPT(...))
removes the FactTable[id]
and dim2[size]
from the filter context when evaluating [Sales]
; so the new filter context is just:
dim1[color] = {"black"}
[Sales]
in this filter context is not BLANK()
, so the row is included in the result.
The proper way to fix this is to wrap the result in an IF
, as you do in your Expected_Results_Color
measure, or to add a filter on [Sales] not Blank
to the table in Power BI.