I need help determining the logic issue with my ‘test’ and '‘What_if_70%’ measure, in particular, how the subtotal is aggregating. The subtotal is not showing the correct output but the row levels are.
In the ‘base data’ table (excel), I have randomized data showing function performance by location. The ideal output is below. The table in PBI should show a group by function and aggregate at subtotal correctly. At row level context, the DAX does what it’s supposed to do, and technically, at subtotal level it does what it should too, but the result is not what I want to see.
What the PBIX matrix looks like:
OUTPUT_%, Numer, and Denom all show the correct row level and subtotal result. But the measure ‘What_if_70_%’ is not showing correct subtotal. It should return [257 + 1,245] = [1,502]. Instead I see [1,305].
Conceptually, to fix the subtotals, I think the idea is to make a virtual table that performs a group by on function, and then to iterate a SUMX over it. I am trying to do the division of (group by sum of [Numer] / group by sum of [Denom]). Then I want to compare if that division result is greater than or equal 70% or 0.70. If it is >= 70%, then use [Numer], if it isn’t, then apply the 70% scenario = [Denom * 0.70]. This works in vacuum and very specific filters built into the logic itself, but fails when I try to interact with slicers on the visualizations page or insert into the matrix.
I spent too many hours on this and I’m at a loss. I feel my failure in asking but I don’t know why I don’t know or understand the answer here. I think the solution is fully around ADDCOLUMNS() and SUMMARIZE() but I am missing the context or not looking at the issue correctly.
OUTPUT_%_DAX =
var Numer = SUM(Performance[Numer])
var Denom = SUM(Performance[Denom])
return
DIVIDE(Numer,Denom)
What_if_70% =
var x = SUM(Performance[Denom]) *0.70
var z = IF([OUTPUT_%_DAX] >= 0.70, SUM(Performance[Numer]),x)
return
z
test =
var sumTable =
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE(Performance,Performance[Function]),
"NUMER", SUM(Performance[Numer]),
"DENOM", SUM(Performance[Denom]),
"OUTPUT_%", DIVIDE(SUM(Performance[Numer]),SUM(Performance[Denom])),
"What_if_70%", IF([OUTPUT_%_DAX] >= 0.70, SUM(Performance[Numer]), SUM(Performance[Denom]) *0.70)
),
ALLSELECTED(Performance[Location]),
ALLSELECTED(Performance[Year]),
ALLSELECTED(Performance[Month]),
ALLSELECTED(Performance[Function])
)
return
SUMX(sumTable,[What_if_70%])
Performance_Tbl_Example.pbix (55.6 KB)