Forum Discussion
Nested IF Statement Ignoring Blanks
- 6 years ago
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
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
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