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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
WSeirafi
Helper I
Helper I

IF statement performance

Hello,

 

I'm witnessing a performance issue for a quite simple measure used in a big table.
If I use this measure, the result is instant

Measure =
VAR CurrentVal = SELECTEDVALUE ( Table[Column] )
RETURN
    CurrentVal
 
However if I use this measure
Measure =
IF (
    ISBLANK (
        SELECTEDVALUE ( Table[Column] )
    ),
    1,
    0
)
 
The visual goes in error after several minutes loading. What is that due to and is there a way around this ?

Regards
7 REPLIES 7
shafiz_p
Super User
Super User

Hi @WSeirafi  With "if" statements, you need to go through each item one by one. When you have a huge table , using "if" statements can be slow. It’s like checking each item individually. The default query timeout is 225 seconds. Please check its performance. Try with switch function, because it faster than "if".

I answered below, unluckily it was not effective

Greg_Deckler
Community Champion
Community Champion

@WSeirafi ISBLANK is notorious for bad performance. Try this:

 

Measure =
IF (
    SELECTEDVALUE ( Table[Column] ) = BLANK(),
    1,
    0
)

 

or

 

Measure =
IF (
    SELECTEDVALUE ( Table[Column] ) <> BLANK(),
    0,
    1
)

or

Measure =
SWITCH( SELECTEDVALUE ( Table[Column] ),
    BLANK(), 1,
    0
)

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I tried with both suggestions you gave

Measure =
VAR CurrentVal = SELECTEDVALUE ( Table[Column] )
RETURN
    SWITCH(CurrentVal,
        BLANK(),1,
        0
    )
Didn't change anything. There is no other way to do this ?
I would have added a calculated column, but this is supposed to be reacting to a slicer

@WSeirafi It's hard to say with the information provided. Would need additional context of the problem you are actually trying to solve. Is this something that could be done using the Filter pane?



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hello,

 

I ended up merging all my data into one big table for this purpose, but my issue now is that when I use a Switch / if measure in my table, the slicer do not have any effect on it.

I guess it's the fact that the IF measure returns a value for every rown but how can I prevent this from happening ?

Thanks for your help

Might be a solution

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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