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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Fredde86
Advocate I
Advocate I

SWITCH measure includes blank/empty rows based on DATEDIFF-column

Hello,

 

I have a datediff column that returns how many days from when my manufacturing orders was actually complete (ITEM_TRANSACTION_HISTORY[Date]) and when the manufacturing order was planned to be complete (MANUFACTURING_ORDERS[Order Due]):

 

Diff days =
DATEDIFF (
    MAXX ( RELATEDTABLE ( MANUFACTURING_ORDERS ), MANUFACTURING_ORDERS[Order Due] ),
    ITEM_TRANSACTION_HISTORY_SUM[Date],
    DAY
)

 

and then I have a SWITCH measure that says if DIFFDAYS are 0 or +-1 day within [Order Due] then that is acceptable/"OK", and if they are complete < -1 day then "Too soon" and > 1 days "Too late":

 

Status Order =
SWITCH(
    TRUE(),
ITEM_TRANSACTION_HISTORY_SUM[Diff days] < -1 , "Too soon" ,
ITEM_TRANSACTION_HISTORY_SUM[Diff days] > 1 , "Too late" ,
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = 1 ||
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = 0 ||
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = -1 , "OK" )
 
The problem I'm having is that I get "OK" when there is no date in my [Order Due]-column. I'm assuming that is because blank = 0 and 0 = "OK" - but I need to filter out these blanks. I tried with a IF( HASONVALUE( ITEM_TRANSACTION_HISTORY_SUM[Diff days] before my SWITCH measure but it didn´t work.
 
Fredde86_1-1731588319609.png

 

 
 
1 ACCEPTED SOLUTION
saud968
Super User
Super User

You can modify your Diff days measure to handle blanks explicitly. Here’s a revised version of your Diff days measure:

Diff days =
IF (
ISBLANK ( MAXX ( RELATEDTABLE ( MANUFACTURING_ORDERS ), MANUFACTURING_ORDERS[Order Due] ) ),
BLANK(),
DATEDIFF (
MAXX ( RELATEDTABLE ( MANUFACTURING_ORDERS ), MANUFACTURING_ORDERS[Order Due] ),
ITEM_TRANSACTION_HISTORY_SUM[Date],
DAY
)
)

This modification checks if the [Order Due] date is blank and returns BLANK() if it is. Otherwise, it calculates the date difference as before.

Next, you can update your Status Order measure to handle these blank values:

Status Order =
SWITCH (
TRUE(),
ISBLANK ( ITEM_TRANSACTION_HISTORY_SUM[Diff days] ), BLANK(),
ITEM_TRANSACTION_HISTORY_SUM[Diff days] < -1, "Too soon",
ITEM_TRANSACTION_HISTORY_SUM[Diff days] > 1, "Too late",
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = 1 ||
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = 0 ||
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = -1, "OK"
)

By adding the ISBLANK check at the beginning of your SWITCH statement, you ensure that any blank values in the Diff days column are handled appropriately and do not return “OK” by default.



Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

View solution in original post

2 REPLIES 2
Kedar_Pande
Super User
Super User

@Fredde86 

Updated Status Order Measure:

Status Order =
SWITCH(
TRUE(),
ISBLANK(RELATED(MANUFACTURING_ORDERS[Order Due])), "No Due Date",
ITEM_TRANSACTION_HISTORY_SUM[Diff days] < -1 , "Too soon",
ITEM_TRANSACTION_HISTORY_SUM[Diff days] > 1 , "Too late",
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = 1 ||
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = 0 ||
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = -1 , "OK"
)

Let me know if you need further assistance!

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

saud968
Super User
Super User

You can modify your Diff days measure to handle blanks explicitly. Here’s a revised version of your Diff days measure:

Diff days =
IF (
ISBLANK ( MAXX ( RELATEDTABLE ( MANUFACTURING_ORDERS ), MANUFACTURING_ORDERS[Order Due] ) ),
BLANK(),
DATEDIFF (
MAXX ( RELATEDTABLE ( MANUFACTURING_ORDERS ), MANUFACTURING_ORDERS[Order Due] ),
ITEM_TRANSACTION_HISTORY_SUM[Date],
DAY
)
)

This modification checks if the [Order Due] date is blank and returns BLANK() if it is. Otherwise, it calculates the date difference as before.

Next, you can update your Status Order measure to handle these blank values:

Status Order =
SWITCH (
TRUE(),
ISBLANK ( ITEM_TRANSACTION_HISTORY_SUM[Diff days] ), BLANK(),
ITEM_TRANSACTION_HISTORY_SUM[Diff days] < -1, "Too soon",
ITEM_TRANSACTION_HISTORY_SUM[Diff days] > 1, "Too late",
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = 1 ||
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = 0 ||
ITEM_TRANSACTION_HISTORY_SUM[Diff days] = -1, "OK"
)

By adding the ISBLANK check at the beginning of your SWITCH statement, you ensure that any blank values in the Diff days column are handled appropriately and do not return “OK” by default.



Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.