Forum Discussion

Cymbolz's avatar
Cymbolz
Helper III
7 years ago
Solved

IF statement unexpected result evaluation

I have "solved" this with a better expression, but am dumbfounded as to why.

 

This is from a colleague, I'm unable to share the pbix without effort so hoping this is sufficient to pin-point the cause.

 

  • Single table data model
  • Report has matrix by several dimension columns and values of several measure
  • Handful of measures, all fairly simple using CALCULATE+ALL or SUM or DIVIDE
  • No iterators
  • Measures re-use other measures

The problem is with this evaluation:

 

[Problem Measure] = IF ( [Measure X] >= 0, [Measure X], 0 )

The logical test appears to be working fine.  But the evaluation of [Measure X] in the result-if-true expression is producing a different result.

 

Eg - the last two rows should simply show as the same value as the first column for [Problem Measure]

 

Measure X     Problem Measure
-10              0
-5               0
-1               0
 0               0
 5             -20
10             -11

The fix was to use a variable and not repeat the measure evaluation.  Which is also better practice.  

 

But I am puzzled why the original expression is not producing the expacted result for [Measure X].  I've broken it down by expanding each measure, run lots of tests and variations in DAX studio to pin-point the issue.  I'm back to bare bones DAX functions and yet it still comes to the evaluation of the true expression behaving differently.  

 

Feels so obvious but I can't think of it...help please?!?!

8 Replies