Forum Discussion
SUMX and variable table not totalling correctly
- 4 years ago
Hi dujhe
Your measure creates a sumtab table, with an added flag column that you use to do the SUMX. However, the test variable that you're using to populate flag isn't being recalculated for each row of sumtab. The value is fixed before sumtab is created and will therefore be the same for each row of sumtab.
What you can do is calculate x, z, and test within the ADDCOLUMNS, so these variables get evaluated for each row of sumtab separately.
Measure 2 = var _1a = SELECTEDVALUE(map_events[EventType]) var _2a = SELECTEDVALUE(map_events2[EventType]) var sumtab = ADDCOLUMNS( SUMMARIZE('test table','test table'[ServiceUserID]), "Flag", var x = CALCULATE( MIN('test table'[EventStartRank]), 'test table'[Eventtype] = _1a) var z = CALCULATE( MIN('test table'[EventStartRank]), 'test table'[EventType] = _2a) var test = IF( x <= z, 1, 0) RETURN test ) Return SUMX(sumtab, [Flag])
Hi dujhe
Your measure creates a sumtab table, with an added flag column that you use to do the SUMX. However, the test variable that you're using to populate flag isn't being recalculated for each row of sumtab. The value is fixed before sumtab is created and will therefore be the same for each row of sumtab.
What you can do is calculate x, z, and test within the ADDCOLUMNS, so these variables get evaluated for each row of sumtab separately.
Measure 2 =
var _1a = SELECTEDVALUE(map_events[EventType])
var _2a = SELECTEDVALUE(map_events2[EventType])
var sumtab =
ADDCOLUMNS(
SUMMARIZE('test table','test table'[ServiceUserID]),
"Flag",
var x = CALCULATE(
MIN('test table'[EventStartRank]),
'test table'[Eventtype] = _1a)
var z = CALCULATE(
MIN('test table'[EventStartRank]),
'test table'[EventType] = _2a)
var test = IF( x <= z, 1, 0)
RETURN test
)
Return
SUMX(sumtab, [Flag])