Forum Discussion

WSeirafi's avatar
WSeirafi
Helper I
1 year ago

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

  • Greg_Deckler's avatar
    Greg_Deckler
    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
    )

     

    • WSeirafi's avatar
      WSeirafi
      Helper I

      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
      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        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?

  • 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".

    • WSeirafi's avatar
      WSeirafi
      Helper I

      I answered below, unluckily it was not effective