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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Nested IF Statement Ignoring Blanks

Hi,

 

Im looking for some help creating a new column to distinguish wether an Appointment was Early, Late or In Target. 

 

I have 3 fields that are going to be used APPOINTMENT ACTUAL_START_DATE, APPOINTMENT_WINDOW_START_DATE and APPOINTMENT_WINDOW_END_DATE. 

 

Im im currently having issues ignoring the blanks in the APPOINTMENT_ACTUAL_START_DATE. Heres what i want to acheive

 

APPTCTGY = IF(AND(APPT[APPOINTMENT_ACTUAL_START_DATE < APPOINTMENT_WINDOW_START_DATE, "EARLY"),
                      IF(AND(APPT[APPOINTMENT_ACTUAL_START_DATE >APPOINTMENT_WINDOW_START_DATE, "LATE"),
                       IF(AND(APPT[APPOINTMENT_ACTUAL_START_DATE >= APPOINTMENT_WINDOW_START_DATE   AND   < =                                     APPOINTMENT_WINDOW_END_DATE , "IN TARGET"))))   
 
 
Any ideas how i can run a statement similar to this ignoring the Blanks in the APPOINTMENT_ACTUAL_START_DATE as this is returning as a "EARLY" when it shouldnt be included.
 
 
Thanks
 
Alex
1 ACCEPTED SOLUTION

Hi @Anonymous 

 

If you're adding this as a calculated column, you don't need all of the MAX functions. They are essentially calculating the max value for that entire column - not what you're after!

 

I always favour the SWITCH function rather than nested IF statements as I find it easier to read.

 

Try adding a calculated column with the expression below:

APPTCTGY =
SWITCH(
    TRUE(),
    ISBLANK( FACT_Appt[APPOINTMENT ACTUAL_START_DATE] ), "EARLY",
    FACT_Appt[APPOINTMENT ACTUAL_START_DATE] < FACT_Appt[APPOINTMENT_WINDOW_START_DATE ], "EARLY",
    FACT_Appt[APPOINTMENT ACTUAL_START_DATE] > FACT_Appt[APPOINTMENT_WINDOW_END_DATE], "LATE",
    FACT_Appt[APPOINTMENT ACTUAL_START_DATE] >= FACT_Appt[APPOINTMENT_WINDOW_START_DATE]
        && FACT_Appt[APPOINTMENT ACTUAL_START_DATE]
            <= MAX(FACT_Appt[APPOINTMENT_WINDOW_END_DATE] ), "IN TARGET"
)

 

Best regards,
Martyn

 

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

could you please share sample dataset and expected output.

 

Why there are to many "AND" in your formula?

 

Thanks,

Pravin

V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could create a measure like this:

APPTCTGY =
IF (
    ISBLANK ( MAX ( 'table'[ APPOINTMENT ACTUAL_START_DATE] ) ),
    "EARLY",
    IF (
        MAX ( 'table'[ APPOINTMENT ACTUAL_START_DATE] )
            < MAX ( 'table'[APPOINTMENT_WINDOW_START_DATE ] ),
        "EARLY",
        IF (
            MAX ( 'table'[ APPOINTMENT ACTUAL_START_DATE] )
                > MAX ( 'table'[APPOINTMENT_WINDOW_END_DATE] ),
            "LATE",
            IF (
                MAX ( 'table'[ APPOINTMENT ACTUAL_START_DATE] )
                    >= MAX ( 'table'[APPOINTMENT_WINDOW_START_DATE ] )
                    && MAX ( 'table'[ APPOINTMENT ACTUAL_START_DATE] )
                        <= MAX ( 'table'[APPOINTMENT_WINDOW_END_DATE] ),
                "IN TARGET"
            )
        )
    )
)

test_if_conditions.PNG

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi,

 

Thanks for your reply.

 

I have followed your code in creating a new column and when the following is applied its returning all values as "EARLY"

 

Capture.PNG

Hi @Anonymous 

 

If you're adding this as a calculated column, you don't need all of the MAX functions. They are essentially calculating the max value for that entire column - not what you're after!

 

I always favour the SWITCH function rather than nested IF statements as I find it easier to read.

 

Try adding a calculated column with the expression below:

APPTCTGY =
SWITCH(
    TRUE(),
    ISBLANK( FACT_Appt[APPOINTMENT ACTUAL_START_DATE] ), "EARLY",
    FACT_Appt[APPOINTMENT ACTUAL_START_DATE] < FACT_Appt[APPOINTMENT_WINDOW_START_DATE ], "EARLY",
    FACT_Appt[APPOINTMENT ACTUAL_START_DATE] > FACT_Appt[APPOINTMENT_WINDOW_END_DATE], "LATE",
    FACT_Appt[APPOINTMENT ACTUAL_START_DATE] >= FACT_Appt[APPOINTMENT_WINDOW_START_DATE]
        && FACT_Appt[APPOINTMENT ACTUAL_START_DATE]
            <= MAX(FACT_Appt[APPOINTMENT_WINDOW_END_DATE] ), "IN TARGET"
)

 

Best regards,
Martyn

 

Anonymous
Not applicable

Thats worked a treat Martyn thanks very much for your help.  This switch funstion is really adaptable and i shall be able to use this in many other areas of my model.

 

Thanks very much

 

Alex

amitchandak
Super User
Super User

You can use Switch True and use isblank to check for blank

Example

Switch (true(),

condition, action,

condition, action,

condition, action,

else action)

 

Anonymous
Not applicable

Thanks. What logiv would you use within the switch to ignore the null values in the ACTUAL_APPOINTMENT)START_DATE field.

 

Thanks

 

Alex

Switch( true(),

isblank(APPOINTMENT_ACTUAL_START_DATE ), "Early",

....

)

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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