Forum Discussion
Anonymous
10 years agoNot applicable
Calculated column with condition returns wrong results (DAX)
Hello, I am trying to use a seemingly straightoforward condition to calculate a new column but I keep getting unexpected results. My database is fairly large but I have created a small dataset where ...
- 10 years ago
Hi Anonymous,
To get the result you want, you can either
- Change the calculated column to:
Column = IF ( Sheet11[Test1] >= CALCULATE ( [Measure2], ALL ( Sheet11 ) ), "Success" )
or - Change the definition of Measure2 to:
Measure2 = CALCULATE ( AVERAGE ( Sheet11[Test2] ), ALL ( Sheet11 ) )
The reason for the original behaviour is:
- All measures are wrapped in an implicit CALCULATE()
- In a row context (such as in a calculatd column), CALCULATE results in context transition of the row context to filter context.
So in your original calculated column, the current row became filter context and [Measure2] ended up returning the average of Test2 in across all rows matching the current row, i.e. in this case just the value of Test2 in the current row. So you got "Success" in rows where Test1 >= Test2.
The fixes above use ALL(Sheet11) to ignore the filter context introduced by context transition, so that [Measure2] is evaluated in the context of an unfiltered table Sheet11.
Hope that helps,
Owen :)
- Change the calculated column to:
Anonymous
10 years agoNot applicable
Thanks a million Owen for the solution and the great explanation! This did the trick!
George.
Sean
10 years agoCommunity Champion
Anonymous An alternative would be to use AVERAGEX like this...
Column = IF ( Sheet11[Test 1] >= AVERAGEX ( ALL ( Sheet11 ), Sheet11[Test 2] ), "Success" )