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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
pe2950
Helper I
Helper I

Chained IF/ELSE across multiple text columns and a date column?

My data model has a SQL table with a bunch of appointments. The appointments have a series of flags that are used to infer the status of the appointment, they are all string columns with a Y or N value, and a date value. 

 

The logic looks like this:

IF isCancelled = Y then "Cancelled"

IF isDeleted = Y then "Deleted"

IF isRescheduled = Y then "Rescheduled"

IF isKept = Y then "Kept"

IF isCancelled = N & isDeleted = N & isRescheduled = N & isKept = N & appointmentDate >= NOW() then "Expected"

IF isCancelled = N & isDeleted = N & isRescheduled = N & isKept = N & appointmentDate < NOW() then "No Show"

 

I'd like to create a calculated columns that more easily allows me to build reports from this data. My goal would be to have the column just display the current status of the appointment. 

 

I can't figure out how to do a bitwise operation in DAX logic. Because of the date constraint do I have to do this with a measure?

 

If i can do it in the query builder instead of a measure, is there a benefit to either?

 

My thinking would be to use a bitwise operation, something where I set the column to 00000 and then flip each bit for the appropriate status? 

 

Is there an easier way?

 

1 ACCEPTED SOLUTION
sokg
Solution Supplier
Solution Supplier

Please create this calculated column in your table

 

LOGIC =
SWITCH (
    TRUE;
    Table1[isCancelled ] = "Y"; "Cancelled";
    Table1[isDeleted ] = "Y"; "Deleted";
    Table1[isRescheduled ] = "Y"; "Rescheduled";
    Table1[isKept ] = "Y"; "Kept";
    Table1[isCancelled ] = "N"
        && Table1[isDeleted ] = "N"
        && Table1[isRescheduled ] = "N"
        && Table1[isCancelled ] = "N"
        && Table1[appointmentDate ] >= NOW (); "Expected";
    Table1[isCancelled ] = "N"
        && Table1[isDeleted ] = "N"
        && Table1[isRescheduled ] = "N"
        && Table1[isCancelled ] = "N"
        && Table1[appointmentDate ] < NOW (); "No Show";
    BLANK ()
)

I try it and works well !!!

 

Capture3.JPG

View solution in original post

1 REPLY 1
sokg
Solution Supplier
Solution Supplier

Please create this calculated column in your table

 

LOGIC =
SWITCH (
    TRUE;
    Table1[isCancelled ] = "Y"; "Cancelled";
    Table1[isDeleted ] = "Y"; "Deleted";
    Table1[isRescheduled ] = "Y"; "Rescheduled";
    Table1[isKept ] = "Y"; "Kept";
    Table1[isCancelled ] = "N"
        && Table1[isDeleted ] = "N"
        && Table1[isRescheduled ] = "N"
        && Table1[isCancelled ] = "N"
        && Table1[appointmentDate ] >= NOW (); "Expected";
    Table1[isCancelled ] = "N"
        && Table1[isDeleted ] = "N"
        && Table1[isRescheduled ] = "N"
        && Table1[isCancelled ] = "N"
        && Table1[appointmentDate ] < NOW (); "No Show";
    BLANK ()
)

I try it and works well !!!

 

Capture3.JPG

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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