Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
zaza
Resolver III
Resolver III

DAX bug or something fundamental I don't get?

Lately I've been running into the weirdest errors. Here is one:

 

Screen Shot 2020-09-18 at 11.09.22 PM.png

I have a simple table with 3 columns (Date, Open, Close) and create a measure to calculate the difference between the Open and Closed (the range):

 

Range = MAX ( 'Table'[Close] ) - MAX ( 'Table'[Open] )

 

 

 

 

 

 

 

 

Now I want to count the number of occurrence of each range.

 

Screen Shot 2020-09-18 at 11.24.48 PM.pngFirst I create a calculated table with the top and bottom range:

 

Gen1 = GENERATESERIES ( -10, 10, 1 )

 

Then I count the rows for each value:

 

Count1 = 
    CALCULATE ( 
        COUNTROWS ( 'Table' ),
        FILTER ( 'Table', [Range] = MAX ( Gen1[Value] ) ) 
    )

 

The results are as expected, nothing seems out of the ordinary (Gen table 1).

 

Now here is the most mind boggling behaviour I found:

 

Screen Shot 2020-09-18 at 11.24.35 PM.png

I slightly modify my calculated table by incrementing by 0.5 instead of 1:

 

Gen2 = GENERATESERIES ( -10, 10, 0.5 )

 

This returns the exact same results as expected (Gen table 2).

 

Finally I change my table again, this time incrementing by 0.1:

 

Gen3 = GENERATESERIES ( -10, 10, 0.1 )

 

But this time the whole calculation breaks (Gen table 3).

 

 

I do not understand why this happens. Either I discovered a bug in DAX or there is something fundamental that I don't understand about DAX as by logic this should not be happening.

 

Edit: Here is the file for reference: PowerBI Mistery.pbix 

1 ACCEPTED SOLUTION

@zaza 

I have come up with a solution! I tested with decimal numbers as well and it works.  Basically, I converted the [Range] measure and the Value from Gen3 Value to 1 decimal as a text result to compare. Test with decimal numbers to confirm.

The new measure:

Count3 = 
    CALCULATE ( 
        COUNTROWS ( 'Table' ),
        FILTER ( 'Table', FIXED([Range],1) = FIXED(MAX ( Gen3[Value] ),1) ) 
    )

Fowmy_0-1600600225919.png

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@zaza 

I have encountered this scenario in a past question and it seems the rounding of decimals by DAX engine has a strange logic.

If you need to have all the numbers from the Gen 3 tables with values, you may try the measure as follows, adjust as per your need. then you get the results as. 

Fowmy_0-1600514359959.png



Count3 = 

    CALCULATE ( 
        COUNTROWS ( 'Table' ),
        FILTER ( 'Table', [Range]  = INT(MAX ( Gen3[Value] ) ) ) 
    )

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy That's not right, I need the count of the numbers that actually appear in my dataset. I also cannot round up the numbers as in my real dataset I will have decimal place numbers.

 

If you say that there is a weird logic how DAX handles decimals, I would like to understand what is going on so I am able to do exact operations on decimal place values.

 

Why does the measure evaluete correctly against the first 2 and not the 3rd? 

 

Gen1 = GENERATESERIES ( -10, 10, 1 ) //works
Gen2 = GENERATESERIES ( -10, 10, 0.5 ) //works
Gen3 = GENERATESERIES ( -10, 10, 0.1 ) //does not work

 

 

@zaza 

I have come up with a solution! I tested with decimal numbers as well and it works.  Basically, I converted the [Range] measure and the Value from Gen3 Value to 1 decimal as a text result to compare. Test with decimal numbers to confirm.

The new measure:

Count3 = 
    CALCULATE ( 
        COUNTROWS ( 'Table' ),
        FILTER ( 'Table', FIXED([Range],1) = FIXED(MAX ( Gen3[Value] ),1) ) 
    )

Fowmy_0-1600600225919.png

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors