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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Vinod_V_12
Frequent Visitor

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?

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
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

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
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

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.