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
OneData
New Member

Power BI version of 'Case When' using "Switch" Function

Hi guys - i'm new to dax and am having a bit oftrouble with what I would like to think should be something simple.

 

Essentially i have paramaters for each bucket listed below and I want those to dynammically fall into one column. I think I've done most of the hard part but I can't seem to put the right measure together. - Is this possible with a measure? I don't think i can add a numeric parameter in the calucalted column in power query so i'm kinda stuck here. Hopefully this is as simple for one of you as it would be for me in sql.

 

What am i doing wrong here?

 

ENLR Delta =
SWITCH(
    TRUE(),
    FILTER('Application','Application'[Fico Range] = "640-679"),([Net Loss Ratio] - [640-679 Value]),
    FILTER('Application]','Application'[Fico Range] = "680-699"),([Net Loss Ratio] - [680-699 Value]),
    FILTER('Application','Application'[Fico Range] = "700-739"),([Net Loss Ratio] - [700-739 Value]),
    FILTER('Application','Application'[Fico Range] = "740-799"),([Net Loss Ratio] - [740-799 Value]),
    FILTER('Application','Application'[Fico Range] = "800+"),([Net Loss Ratio] - [800+ Value]),
    0
)
1 ACCEPTED SOLUTION
OneData
New Member

Fixed it - looks like instead of filter - using contains worked just fine for me - hope this helps someone in the future!

 

ENLR Delta =
SWITCH(
    TRUE(),
    CONTAINS('Application','Application'[Fico Range] = "640-679"),([Net Loss Ratio] - [640-679 Value]),
    CONTAINS('Application]','Application'[Fico Range] = "680-699"),([Net Loss Ratio] - [680-699 Value]),
    CONTAINS('Application','Application'[Fico Range] = "700-739"),([Net Loss Ratio] - [700-739 Value]),
    CONTAINS('Application','Application'[Fico Range] = "740-799"),([Net Loss Ratio] - [740-799 Value]),
    CONTAINS('Application','Application'[Fico Range] = "800+"),([Net Loss Ratio] - [800+ Value]),
    0
)

View solution in original post

3 REPLIES 3
OneData
New Member

Fixed it - looks like instead of filter - using contains worked just fine for me - hope this helps someone in the future!

 

ENLR Delta =
SWITCH(
    TRUE(),
    CONTAINS('Application','Application'[Fico Range] = "640-679"),([Net Loss Ratio] - [640-679 Value]),
    CONTAINS('Application]','Application'[Fico Range] = "680-699"),([Net Loss Ratio] - [680-699 Value]),
    CONTAINS('Application','Application'[Fico Range] = "700-739"),([Net Loss Ratio] - [700-739 Value]),
    CONTAINS('Application','Application'[Fico Range] = "740-799"),([Net Loss Ratio] - [740-799 Value]),
    CONTAINS('Application','Application'[Fico Range] = "800+"),([Net Loss Ratio] - [800+ Value]),
    0
)
FreemanZ
Super User
Super User

hi @OneData 

what contexts do you have for the measure? Or how are you going to present this measure?

Similarly to case when - it will be presented in a single column - however for each bucket i need each desired input. I was able to accomplish this in power query during etl on a another column in the dataset but this one here depends on numeric parameters so i have to figure out a measure to accomplish the "case when" scenario

 

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