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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
sai1995
Employee
Employee

DAX Formula using TreatAS contains a BUG

I have a modell which use in DAX Formula TreatAs. However it computes wrong results. I have made a comparison with userelationship. That is working well.
It seems that TreatAs is not evaluating 2 records out of 5.7 Mio.

Please see the Report Tab Error Error "UseRelationship vs TreatAS".
The measure Bilanz is using UseRelationship and works correct
The measure Bilanz TreatAS is using TreatAS and not shows correct Data.

Both measures should display the same amount. It works well for all Accounts except of Account "15400 Baumaschinen". There it seems that TreatAs is not see 2 Records in Table Buchungen. (See Screenshot).

Can you please Debut the DAX Formula engine and see why Bilanz TreatAS is not showing the correct result?

7 REPLIES 7
miraglia
Advocate I
Advocate I

After reviewing the DAX Code and the Data the following code resolved the Problem:

Bilanz =

CALCULATE(
    SUM('Buchungen'[Betrag]),
    FILTER(
        ALL('Zeitachse'),
        ISONORAFTER('Zeitachse'[Datum], MAX('Zeitachse'[Datum]), DESC)
    ), Kontenplan[GuV_Bilanz] =1, ALL(Kostenstellen)
,TREATAS(VALUES(Mandanten[Konzernmandant]), Buchungen[Konzernmandant]))
 
There was a relationship between Buchungen to Kostenstellen to Mandanten which filterd 2 records out of 5.7 Mio records because the Kostenstelle in Buchungen was not a valid one.....
Anonymous
Not applicable

As I said, it's roughly the lack of knowledge about how DAX works that was at fault, not DAX itself. Many people I've been in touch with have claimed that DAX does not work correctly or that it has bugs :))) But the story is always the same. Glad you've been able to squash "the bug" 🙂

sai1995
Employee
Employee

Hi @Anonymous please answer for above question raised by @miraglia 

Anonymous
Not applicable

What screenshot, errors and tabs are you talking about? There's nothing like that in here... By the way, as is usual with DAX, I'm 100% sure it's your misunderstanding of what DAX is doing is at fault here and not DAX itself.

One DAX Measure is:

Bilanz =
CALCULATE(
    SUM('Buchungen'[Betrag]),
    FILTER(
        ALL('Zeitachse'),
        ISONORAFTER('Zeitachse'[Datum], MAX('Zeitachse'[Datum]), DESC)
    ), Kontenplan[GuV_Bilanz] =1
,USERELATIONSHIP(Buchungen[Konzernmandant], Mandanten[Konzernmandant] ))
 
and the other is:
Bilanz TreatAS =
CALCULATE(
    SUM('Buchungen'[Betrag]),
    FILTER(
        ALL('Zeitachse'),
        ISONORAFTER('Zeitachse'[Datum], MAX('Zeitachse'[Datum]), DESC)
    ), Kontenplan[GuV_Bilanz] =1
,TREATAS(VALUES(Mandanten[Konzernmandant]), Buchungen[Konzernmandant]))
 
They are showing different Results, but according to the Microsoft Documentation both Measures should produce the same result.
Anonymous
Not applicable

Here's a simple example to show you that your measures do not necessarily have to be logically equivalent:

 

daxer_0-1626340866628.png

daxer_1-1626340930844.pngdaxer_2-1626340960222.pngdaxer_3-1626340979945.png

Count With Relationship = COUNTROWS( 'Fact' )

Count With Treatas = 
    CALCULATE(
        COUNTROWS( 'Fact' ),
        CROSSFILTER( 'Fact'[Item], Items[Item], None ),
        TREATAS(
            VALUES( Items[Item] ),
            'Fact'[Item]
        )
    )
Anonymous
Not applicable

To be able to say if anything is really wrong with DAX I need data that demonstrates the issue. Without the data I can't say anything but what I've already said. One thing to note immediately is the fact that in the first formula you are making a connection active (and probably deactivate another one) and in the other no such thing takes place. That means you've got two different situations. I would have to analyze the interplay among all the pieces that make up the code.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors