Forum Discussion

Vinod_V_12's avatar
Vinod_V_12
Frequent Visitor
5 years ago
Solved

Switch syntax causing issues with loading visuals

Hi,

 

Please could you help me to simply the below DAX. Our Dataset is connected to SAP HANA via direct query. The visual is not getting loaded as the query is consuming a lot of profile memory allocated in HANA. On the analysis, it was found that this switch syntax is causing the issue. 

 

Suppress Sales Switch =

SWITCH(

SELECTEDVALUE('Total Sales Slicer'[Total Sales Criteria]) ,

"Total Sales = 0", if([Suppress Sales] = 0, [Suppress Sales], BLANK()),

"Total Sales < 0", if([Suppress Sales] < 0, [Suppress Sales], BLANK()),

"Total Sales > 0", if([Suppress Sales)] > 0, [Suppress Sales], BLANK()),

"Total Sales <> 0", if([Suppress Sales] <> 0, [Suppress Sales)], BLANK()),

[Suppress Sales]

)

 

The above is used as a visual filter and the condition is set to "is not blank". The field Total Sales Criteria is then used in a slicer as the business wants to filter the data by total sales =0, >0,<0,<>0 and All

 

Suppress Sales = sumx('Calculated Measures',abs(COALESCE([Value Field 1],0)) + abs(COALESCE([Value Field 2],0))+ abs(COALESCE([Value Field 3],0)))

 

Total Sales Slicer Table:

Total Sales CriteriaFlag
Total Sales All0
Total Sales <01
Total Sales = 02
Total Sales >03
Total Sales <>04

 

Any advise to replace Switch which is causing the issue?

  • That measure (and the one it references) might need more optimization but for starters, you can use a variable like this to reduce to amount of re-calculation.

     

    Suppress Sales Switch =
    VAR Suppress = [Suppress Sales]
    RETURN
        SWITCH (
            SELECTEDVALUE ( 'Total Sales Slicer'[Total Sales Criteria] ),
            "Total Sales = 0"IF ( Suppress = 0SuppressBLANK () ),
            "Total Sales < 0"IF ( Suppress < 0SuppressBLANK () ),
            "Total Sales > 0"IF ( Suppress > 0SuppressBLANK () ),
            "Total Sales <> 0"IF ( Suppress <> 0SuppressBLANK () ),
            Suppress
        )

     

    Pat

     

2 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    That measure (and the one it references) might need more optimization but for starters, you can use a variable like this to reduce to amount of re-calculation.

     

    Suppress Sales Switch =
    VAR Suppress = [Suppress Sales]
    RETURN
        SWITCH (
            SELECTEDVALUE ( 'Total Sales Slicer'[Total Sales Criteria] ),
            "Total Sales = 0"IF ( Suppress = 0SuppressBLANK () ),
            "Total Sales < 0"IF ( Suppress < 0SuppressBLANK () ),
            "Total Sales > 0"IF ( Suppress > 0SuppressBLANK () ),
            "Total Sales <> 0"IF ( Suppress <> 0SuppressBLANK () ),
            Suppress
        )

     

    Pat

     

    • Vinod_V_12's avatar
      Vinod_V_12
      Frequent Visitor

      Thanks very much for the response Pat. This is brilliant.