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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors