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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
rgoo
Frequent Visitor

SWITCH statement not working as intended

i have a switch statment using DAX: 

DisplaySEAData = 
SWITCH(
    TRUE(),
    [SEA Selected],CALCULATE(SUM('EVR 2014-2024'[EVR]),'EVR 2014-2024'[office_name] = "SEA"),
   "Test"
)

 

SEA Selected = 
VAR SelectedCountries = VALUES('EVR 2014-2024'[office_name])
VAR CountSelectedCountries = COUNTROWS(SelectedCountries)
RETURN 
IF (
    CountSelectedCountries = 4 &&
    COUNTROWS(FILTER(SelectedCountries, 'EVR 2014-2024'[office_name] IN {"Vietnam", "Philippines", "Indonesia","Thailand"})) = 4,
    TRUE(),
    FALSE()
)

In this scenario nothing is selected, so "test" is shown which is correct

rgoo_0-1715678896678.png

 

However when the SEA countries are selected in the slicer, it returns blank but [SEA Selected] is already returning True as seen on the card on the left

rgoo_1-1715678908820.png

 

I have also checked that CALCULATE(SUM('EVR 2014-2024'[EVR]),'EVR 2014-2024'[office_name] = "SEA") returns a value and not a blank

rgoo_5-1715678461009.png

 

Can someone help me figure out what is wrong with my logic as to why its returning blank when it clearly is not?
Appreciate the help in advance

1 ACCEPTED SOLUTION
rgoo
Frequent Visitor

i found the issue, as i am selecting the slicer I.e. Vietnam,Indonesia, Thailand.  i want to display the sum from  SEA region instead but as it is filtered for Vietnam,Indonesia, Thailand it shows as blank() instead. i am now going to try and see if can do it if i change my data source to another table

 

View solution in original post

4 REPLIES 4
Sergii24
Super User
Super User

Hi @rgoo, I'd suggest to debug in the following way:

  1. "DisplaySEAData" measure: replace "CALCULATE(SUM('EVR 2014-2024'[EVR]),'EVR 2014-2024'[office_name] = "SEA")" with a static value, for instance 1 (or text "1" in your case as your else parameter "test" is a string value). In this way you can verify whether switch works as expected.
  2. If switch works and you get value 1, then the problem is with Calcualte(). Make sure that you apply exactly same filters when testing it alone as when "DisplaySEAData".
  3. If not, so with "1" switch still provides you Blank(), then rewrite your formula with variable (I'm not sure if switch is evaluating a measure when used as a "value" argument 
DisplaySEAData = 
VAR _SEA_Selected = [SEA Selected]
RETURN
SWITCH(
    TRUE(),
    _SEA_Selected,CALCULATE(SUM('EVR 2014-2024'[EVR]),'EVR 2014-2024'[office_name] = "SEA"),
   "Test"
)


I hope something from it will help you! Good luck 🙂

rgoo
Frequent Visitor

i found the issue, as i am selecting the slicer I.e. Vietnam,Indonesia, Thailand.  i want to display the sum from  SEA region instead but as it is filtered for Vietnam,Indonesia, Thailand it shows as blank() instead. i am now going to try and see if can do it if i change my data source to another table

 

Great! Remember to acceprt the relevant asnwer as a solution when you finish, so others can find an answer to similar problem 🙂

johnbasha33
Super User
Super User

@rgoo  did you check the interaction between them? 

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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