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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
JenWilson
Helper II
Helper II

Days between dates not showing negatives

The calculation below is giving the correct number of days between my fact table columns (DateProduced and DateShipped) but only if the DateProduced is earlier than the DateShipped. If the DateProduced is any date after DateShipped, I get a -1 (due to the last part of the formula below, else it would be blank). So if the DateProduced is 8/26/24 and the DateShipped is 8/27/24 or 8/28/2024 it will always show -1. What I need it to show is the true negative value for the dates between those dates. Note the calendar table is already identifying weekdays as the first part of my formula below shows. 

 

What can I add to this formula to correctly display the negative days between?

 

DaysEarly/Late = CALCULATE(SUM(Calendar[WeekDays]),DATESBETWEEN(Calendar[Date],FactTable[DateProduced],FactTable[DateShipped]))-1

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

maybe you can try this

if (FactTable[DateProduced]<=FactTable[DateShipped], CALCULATE(SUM(Calendar[WeekDays]),DATESBETWEEN(Calendar[Date],FactTable[DateProduced],FactTable[DateShipped])), CALCULATE(SUM(Calendar[WeekDays]),DATESBETWEEN(Calendar[Date],FactTable[DateShipped],FactTable[DateProduced]))*-1)

 

if the produced date is earlier than ship date, then use the current foumula, else change the position of these two dates in the existing formular and * -1 to get a negative day number

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
ryan_mayu
Super User
Super User

maybe you can try this

if (FactTable[DateProduced]<=FactTable[DateShipped], CALCULATE(SUM(Calendar[WeekDays]),DATESBETWEEN(Calendar[Date],FactTable[DateProduced],FactTable[DateShipped])), CALCULATE(SUM(Calendar[WeekDays]),DATESBETWEEN(Calendar[Date],FactTable[DateShipped],FactTable[DateProduced]))*-1)

 

if the produced date is earlier than ship date, then use the current foumula, else change the position of these two dates in the existing formular and * -1 to get a negative day number

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Your solution didn't quite work. I did something similar as below and I am getting the desired results.

Prod to Req Ship Days =
VAR _DateDiffEarly = CALCULATE(SUM(Calendar[WeekDays]),DATESBETWEEN(Calendar[Date],FactTable[DateShipped],FactTable[DateProduced]))-1
VAR _DateDiffLate = CALCULATE(SUM(Calendar[WeekDays]),DATESBETWEEN(Calendar[Date],FactTable[DateProduced],FactTable[DateShipped]))-1
RETURN IF(_DateDiffEarly>=0,_DateDiffEarly,_DateDiffLate*-1)
 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors