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, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Tomo2709
Regular Visitor

Nested switch statements?

Hi 

I have two conditional columns [FROMDASHBOARDSTATUS] AND [FROMOFFSHORESTATUS]

 

I am trying to apply some logic to different scenarios depending upon the result in either [FROMDASHBOARDSTATUS] or[FROMOFFSHORESTATUS].  The DAX formulae i have is:

 

FINALSTATUS = SWITCH(
       TRUE(),
       'PFUpdates'[FROMDASHBOARDSTATUS]="Approved - Modified",'Panel Firm Updates'[FROMOFFSHORESTATUS],
       'PFUpdates'[FROMDASHBOARDSTATUS]="Approved - Paid in Full",'Panel Firm Updates'[FROMOFFSHORESTATUS],
       'PFUpdates'[FROMDASHBOARDSTATUS]="Unapproved","Awaiting approval in Dashboard",
       'PFUpdates'[FROMDASHBOARDSTATUS]="Disputed","Disputed in Dashboard",
       'PFUpdates'[FROMDASHBOARDSTATUS]="Rejected","Rejected in Dashboard",
       'PFUpdates'[FROMDASHBOARDSTATUS]="Reversal","Reversal in Dashboard",
       'PFUpdates'[FROMDASHBOARDSTATUS]=BLANK(),"No Record",
       'PFUpdates'[FROMDASHBOARDSTATUS]="Unknown",'Panel Firm Updates'[FROMOFFSHORESTATUS])

 

The above works ok apart from one niggling issue (ill explain below) also, i would like to  add one more statement:

'PFUpdates'[FROMOFFSHORESTATUS]="Unknown","Unknown" but i beleive i cant add this because the starting value ( 'PFUpdates'[FROMDASHBOARDSTATUS]) is a different conditional column to the rest.  I thought a nested switch statement would help to add this additional value but i dont know if that is possible?  If anyone can advise that would be great.  

 

Regarding the niggling issue..... the statement above " 'PFUpdates'[FROMDASHBOARDSTATUS]="Approved - Paid in Full",'PFUpdates'[FROMOFFSHORESTATUS]," is basically stating if  'PFUpdates'[FROMDASHBOARDSTATUS] has a value "Approved - Paid in Full" then use the corresponding entry result found in 'PFUpdates'[FROMOFFSHORESTATUS] but... my question is if  'PFUpdates'[FROMOFFSHORESTATUS] is BLANK() then i would like the result to be "Transferred to EDM".  Am i able to modify the statement to also look for the blank values in 'PFUpdates'[FROMOFFSHORESTATUS] after it has looked for "Approved - Paid in Full" in 'PFUpdates'[FROMDASHBOARDSTATUS].

 

Any help greatly appreciated and i hope this is not too confusing?

 

Paul 

 

InkedBI SNAPHOT_LI.jpg

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

I think adding IF would be sufficient, also I'm not sure about order of conditions for the Unknown - is it as you expected?

FINALSTATUS =
IF (
    'PFUpdates'[FROMOFFSHORESTATUS] = "Unknown",
    "Unknown",
    SWITCH (
        'PFUpdates'[FROMDASHBOARDSTATUS],
        "Approved - Modified", 'Panel Firm Updates'[FROMOFFSHORESTATUS],
        "Approved - Paid in Full", IF (
            ISBLANK ( 'Panel Firm Updates'[FROMOFFSHORESTATUS] ),
            "Transferred to EDM",
            'Panel Firm Updates'[FROMOFFSHORESTATUS]
        ),
        "Unapproved", "Awaiting approval in Dashboard",
        "Disputed", "Disputed in Dashboard",
        "Rejected", "Rejected in Dashboard",
        "Reversal", "Reversal in Dashboard",
        BLANK (), "No Record",
        "Unknown", 'Panel Firm Updates'[FROMOFFSHORESTATUS]
    )
)


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

3 REPLIES 3
Stachu
Community Champion
Community Champion

I think adding IF would be sufficient, also I'm not sure about order of conditions for the Unknown - is it as you expected?

FINALSTATUS =
IF (
    'PFUpdates'[FROMOFFSHORESTATUS] = "Unknown",
    "Unknown",
    SWITCH (
        'PFUpdates'[FROMDASHBOARDSTATUS],
        "Approved - Modified", 'Panel Firm Updates'[FROMOFFSHORESTATUS],
        "Approved - Paid in Full", IF (
            ISBLANK ( 'Panel Firm Updates'[FROMOFFSHORESTATUS] ),
            "Transferred to EDM",
            'Panel Firm Updates'[FROMOFFSHORESTATUS]
        ),
        "Unapproved", "Awaiting approval in Dashboard",
        "Disputed", "Disputed in Dashboard",
        "Rejected", "Rejected in Dashboard",
        "Reversal", "Reversal in Dashboard",
        BLANK (), "No Record",
        "Unknown", 'Panel Firm Updates'[FROMOFFSHORESTATUS]
    )
)


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Hey Stachu - great to hear from you again.  Ill give your solution a go - will get back to you in a tick 🙂

 

Paul 

Hi

 

I know i have said it before in other posts but ill say it again - you are a star.  Thank you so much.  I never thought about an if statement 🙂 !

 

Paul 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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