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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Multiple criteria for switch statement

I'm really struggling to get my head round this SWITCH statment, may not be possible in one calculated column? I've written it in SQL below as a case statment and it works but cant do the same in DAX. I believe SWITCH would be the best function to use and have tried nesting IF statetments in there as well with no luck.

 

Any help greatly appreciated!

 

case when A is null and B in ('1',2','3','4','5') then 'Global'

        when A in ('11',12','13') and B is null or B = '6' then 'Local'

        when A is null and B is null or B = '6' and DIM.C not in ('98','99') then 'Customer'

        when A is null and B is null or B = '6' and DIM.C = '98' then 'Other' else 'NA' end as 'Category' 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 
This is a formula for a calculated column

Switch Statement =
SWITCH (
    TRUE (),
    TableName[A] = BLANK ()
        && TableName[B] IN { 1, 2, 3, 4, 5 }, "Global",
    TableName[A]
        IN { 11, 12, 13 }
            && OR ( TableName[B] = BLANK (), TableName[B] = 6 ), "Local",
    TableName[A] = BLANK ()
        && OR ( TableName[B] = BLANK (), TableName[B] = 6 )
        && NOT ( RELATED ( DIM[C] ) IN { 98, 99 } ), "Customer",
    TableName[A] = BLANK ()
        && OR ( TableName[B] = BLANK (), TableName[B] = 6 )
        && RELATED ( DIM[C] ) = 98, "Other",
    "NA"
)

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Anonymous 
This is a formula for a calculated column

Switch Statement =
SWITCH (
    TRUE (),
    TableName[A] = BLANK ()
        && TableName[B] IN { 1, 2, 3, 4, 5 }, "Global",
    TableName[A]
        IN { 11, 12, 13 }
            && OR ( TableName[B] = BLANK (), TableName[B] = 6 ), "Local",
    TableName[A] = BLANK ()
        && OR ( TableName[B] = BLANK (), TableName[B] = 6 )
        && NOT ( RELATED ( DIM[C] ) IN { 98, 99 } ), "Customer",
    TableName[A] = BLANK ()
        && OR ( TableName[B] = BLANK (), TableName[B] = 6 )
        && RELATED ( DIM[C] ) = 98, "Other",
    "NA"
)
Anonymous
Not applicable

Amazing, thank you!!

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Users online (29)