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
smpa01
Super User
Super User

JS like loose and strict equality comparer in DAX ?

Hello,

 

Based on what I discovered here @https://community.powerbi.com/t5/Desktop/DAX-to-return-seperate-values-for-0-and-BLANK/m-p/1081709#M...

 

xs.PNG

 

 

 

testing if blank previous = IF([Value]=BLANK(),"true","false")

testing if blank now = IF([Value]==BLANK(),"true","false")

 

 

and thanks to

@harshnathani

@ruthpozuelo

 

 

does DAX has same JS like strict and loose equality comparer.

Capture.PNG

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Well, this is strange. Figured this could be solved by doing something like:

Loose = 
    IF(
        ISERROR(IF([Column1]=[Column3],TRUE(),FALSE())),
        IF([Column1]+0=[Column2]+0,TRUE(),FALSE()),
        IF([Column1]=[Column3],TRUE(),FALSE())
    )

or

Strict = 
    IFERROR(
        IF([Column1]=[Column3],TRUE(),FALSE()),
        FALSE()
    )

But if though things are wrapped in IFERROR statements or testing for ISERROR, you still get back the error that DAX comparison operators do not support comparing integers and Text. So, that seems like a bug...

 

But, you could implement them this way:

Loose1 = 
    IF( (ISTEXT([Column1]) && ISNUMBER([Column2])) || (ISTEXT([Column2]) && ISNUMBER([Column1])),
        IF([Column1]+0 = [Column2]+0,TRUE(),FALSE()),
        IF([Column1] = [Column2],TRUE(),FALSE())
    )

Strict1 = 
    IF( (ISTEXT([Column1]) && ISNUMBER([Column3])) || (ISTEXT([Column3]) && ISNUMBER([Column1])),
        FALSE(),
        IF([Column1] = [Column2],TRUE(),FALSE())
    )

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Well, this is strange. Figured this could be solved by doing something like:

Loose = 
    IF(
        ISERROR(IF([Column1]=[Column3],TRUE(),FALSE())),
        IF([Column1]+0=[Column2]+0,TRUE(),FALSE()),
        IF([Column1]=[Column3],TRUE(),FALSE())
    )

or

Strict = 
    IFERROR(
        IF([Column1]=[Column3],TRUE(),FALSE()),
        FALSE()
    )

But if though things are wrapped in IFERROR statements or testing for ISERROR, you still get back the error that DAX comparison operators do not support comparing integers and Text. So, that seems like a bug...

 

But, you could implement them this way:

Loose1 = 
    IF( (ISTEXT([Column1]) && ISNUMBER([Column2])) || (ISTEXT([Column2]) && ISNUMBER([Column1])),
        IF([Column1]+0 = [Column2]+0,TRUE(),FALSE()),
        IF([Column1] = [Column2],TRUE(),FALSE())
    )

Strict1 = 
    IF( (ISTEXT([Column1]) && ISNUMBER([Column3])) || (ISTEXT([Column3]) && ISNUMBER([Column1])),
        FALSE(),
        IF([Column1] = [Column2],TRUE(),FALSE())
    )

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hello@Greg_Deckler ,

 

Thanks, you put a lot of work in this and I learnt a lot from here.

 

My experience of working with DAX tells me that the following test

 

Integer=1 is not equal to Text='1'

 

DAX considers BLANK()=0, when I was trying to distinguish BLANK() from 0 it did not work with = till I used ==.

I wonder why DAX did that as if DAX does a JS like behaviour when it puts 0 in it's blind spot while doing the euality compariosn with = but not with ==.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Yeah, they just recently added the == operator like in Feb or March release, it's been really recent.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I posted this to the Issues forum here: https://community.powerbi.com/t5/Issues/IFERROR-and-ISERROR-do-not-work-with-comparisons-between-typ...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.