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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors