Forum Discussion
Crossjoins behaving unexpectedly
Hi,
I have a problem trying to roll up values in Power BI. What I am trying to accomplish:
- I have a list of hours booked on a certain day by a certain person in multiple lines.
- Roll up the lines by date and person into a single number of hours on that day
- Check a slicer value and see if the amount of hours is smaller than that value
- If so, return 1 else return 0
What I have currently tried:
Result = SUMX(CROSSJOIN(values([Name]),VALUES([Date]), IF(calculate(SUM([Hours])<SELECTEDVALUE(MySlicer),1,0))
The result is below:
I also added the comparison values. As you can see they are flawless. However, the result for June 10 is off. This should evaluate to 0. Can anyone help me with what is going wrong here? Because I am at a total loss.
Found the solution. The problem is caused by a well known problem of comparing two floating point numbers. Both numbers need to be explicitly rounded to 2 digits for it to work. A night of sleep can do a lot of good. Thanks for responding!
4 Replies
- Ashish_MathurSuper User
Hi,
Why not simply use
=IF(calculate(SUM([Hours])<SELECTEDVALUE(MySlicer),1,0)
Hope this helps.
- SemGAdvocate I
Hi,
Thanks for responding. Because the grand total evaluates to 0 if you just use IF. Also, I just checked an it had the same problem. Certain values that clearly need to get evaluated to 0 get evaluated to 1. Anyone?
- SemGAdvocate I
Found the solution. The problem is caused by a well known problem of comparing two floating point numbers. Both numbers need to be explicitly rounded to 2 digits for it to work. A night of sleep can do a lot of good. Thanks for responding!