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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Multiple IF statements inside switch case

I have multiple statements that i need to validate for "category" column.
I have written this DAX but i am getting an error "Switch doesnot support comparing values of type boolean with text ,consider using value or format to convert one of the values"
Category =
var cat_raw = 'Data'[Category_Raw]
var new = SWITCH (
TRUE (),
IF(AND('Data'[Facility] starts with "AB",OR('Data'[Payer] contains ="XXXX",
'Data'[Payer] contains = "XYXY")), "XContainer","XService"),
IF(AND('Data'[Facility] = "BC",OR('Data'[Type]="YYYY",
'Data'[Type]="YXYX")), "YContainer",cat_raw),
IF(AND('Data'[Facility] = "CD",'Data'[Type]="CDCD"),
"DContainer", cat_raw),
cat_raw
)
return new
1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @Anonymous 

the first part has random non-DAX code like "starts with". For the secodn part, you'd need something like this. You'll probably have to adapt it a bit but you'll get the idea.

Category =
VAR cat_raw = 'Data'[Category_Raw]
VAR new =
    SWITCH (
        TRUE (),
        AND (
            'Data'[Facility] = "BC",
            OR ( 'Data'[Type] = "YYYY", 'Data'[Type] = "YXYX" )
        ), "YContainer",
        AND ( 'Data'[Facility] = "CD", 'Data'[Type] = "CDCD" ), "DContainer",
        cat_raw
    )
RETURN
    new

 Look at the syntax of SWITCH to understand well how it works

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

View solution in original post

5 REPLIES 5
V-pazhen-msft
Community Support
Community Support

@Anonymous 

Can you explain with a short sample table, so we can understand the code. 

 

Regards
Paul

AlB
Super User
Super User

@Anonymous 

1) Let me see the actual code.

2) Check that none of the columns you are comparing to text are of type boolean

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

Anonymous
Not applicable

All my columns are of type TEXT, i have checked it already

AlB
Super User
Super User

Hi @Anonymous 

the first part has random non-DAX code like "starts with". For the secodn part, you'd need something like this. You'll probably have to adapt it a bit but you'll get the idea.

Category =
VAR cat_raw = 'Data'[Category_Raw]
VAR new =
    SWITCH (
        TRUE (),
        AND (
            'Data'[Facility] = "BC",
            OR ( 'Data'[Type] = "YYYY", 'Data'[Type] = "YXYX" )
        ), "YContainer",
        AND ( 'Data'[Facility] = "CD", 'Data'[Type] = "CDCD" ), "DContainer",
        cat_raw
    )
RETURN
    new

 Look at the syntax of SWITCH to understand well how it works

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

Anonymous
Not applicable

Sorry about the non dax part, it was for my understanding which i will do it later , to search and to use contain in dax query .So for the time being i am using "=" only , and i also tried removing the IF statements and i am still getting the same error

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors