Forum Discussion
dujhe
4 years agoRegular Visitor
SUMX and variable table not totalling correctly
Hi, I apologise if this has been asked previously but I have searched and cannot seem to find anything that I can relate to. I'm having an issue using SUMX on a table variable in a DAX measure. It...
- 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])
dujhe
4 years agoRegular Visitor
AH that makes sense now!
Thank you so much as this was driving me mad.