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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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