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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Switch with multiple conditions

Hi all,

 

I have a new column definition [BedCount] written in DAX using several nested IF statements. I wanted to implement SWITCH to make things cleaner, but I couldn't wrap my head around how I would implement an AND in SWITCH. Any guideance on how to re-write this with SWITCH would be appreciated. I'd like to figure out how to do this as a Measure too, but was having trouble wrapping my head around the appropriate context. Having it added as a column "works" so the Measure piece is more about just getting better at Filter & Row context.

 

For more context, this column is currently added to the table 'prog_ProposeProg'. Basic star schema with the other two referenced tables having a direct relationship to 'prog_ProposeProgram'.

 

VAR SubCategory = RELATED(prog_CatSub[Name])
VAR Category = RELATED(prog_Categories[Name])

RETURN
    IF(
        AND(
            CONTAINSSTRING(SubCategory, "Acute"),
            CONTAINSSTRING(Category, "Inpatient")
        ),
        prog_ProposeProgram[Target Area] / [Acute Inpatient],
        
        IF(
            AND(
                CONTAINSSTRING(SubCategory, "Critical"),
                CONTAINSSTRING(Category, "Inpatient")
            ),
            prog_ProposeProgram[Target Area] / [Critical Bed],
            
            IF(
                AND(
                    CONTAINSSTRING(SubCategory, "Rehab"),
                    CONTAINSSTRING(Category, "Inpatient")
                ),
                prog_ProposeProgram[Target Area] / [Rehab Bed],
                BLANK()
        )
    )
)

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Use SWITCH(TRUE()...) like:

 

SWITCH(TRUE(),

  <condition1> && <condition2>,<result1>,

  <condition3> && <condition4>,<result2>

  <default result>

)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Use SWITCH(TRUE()...) like:

 

SWITCH(TRUE(),

  <condition1> && <condition2>,<result1>,

  <condition3> && <condition4>,<result2>

  <default result>

)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

duh! Thanks!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.