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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Counting working days between two dates

Hi, I'm using the following formula to calculate working dates between two dates. It works great if the PickedDate comes after Delivery date. However, the formula returns a 0 instead of the negative value, which is expected, when the PickedDate comes before the DeliveryDate. As the result, the DeliveryDaysVariance is always positive. Please help me create a formula that will generate either positive or negative variance depending whether the PickedDate comes before or after the DeliveryDate. I need to count only working days, so I created a the IsWorkDay column in my RollingDate table that mark working days as 1.

 

DeliveryDaysVariance = CALCULATE(SUM(RollingDate[IsWorkDay]),
                                    DATESBETWEEN(RollingDate[Date],
                                    Invoices[DeliveryDate],
                                    Invoices[PickedDate])) + 0

Thank you!

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

 

Hi,

 

Try if the following codes work for you...

 

DeliveryDaysVariance =
CALCULATE (
    SUM ( RollingDate[IsWorkDay] ),
    DATESBETWEEN ( RollingDate[Date], MIN(Invoices[DeliveryDate], Invoices[PickedDate]),MAX(Invoices[DeliveryDate], Invoices[PickedDate]) )
)
    + 0 

View solution in original post

Anonymous
Not applicable

I made your formula work by adding a conditional column in the query edit. This column has -1 when the PickDate is prior to the DeliveryDate and 1 when it's after. Thank you!

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

 

Hi,

 

Try if the following codes work for you...

 

DeliveryDaysVariance =
CALCULATE (
    SUM ( RollingDate[IsWorkDay] ),
    DATESBETWEEN ( RollingDate[Date], MIN(Invoices[DeliveryDate], Invoices[PickedDate]),MAX(Invoices[DeliveryDate], Invoices[PickedDate]) )
)
    + 0 
Anonymous
Not applicable

I made your formula work by adding a conditional column in the query edit. This column has -1 when the PickDate is prior to the DeliveryDate and 1 when it's after. Thank you!
Anonymous
Not applicable

Thanks for your response. That's an iteresting solution but it doens't indicate negative variances when the PickDate is prior to DeliveryDate. Your code returns only positive variances. I just wrote the following code which seems to do the job. I was hoping there was a more elegant way of achieving the same result:

 

DeliveryDaysVariance = IF(Invoices[PickedDate]>Invoices[DeliveryDate]  
                                    ,CALCULATE(SUM(RollingDate[IsWorkDay]),
                                                    DATESBETWEEN(RollingDate[Date],
                                                    Invoices[DeliveryDate],
                                                    Invoices[PickedDate])) + 0
                                    ,-1*CALCULATE(SUM(RollingDate[IsWorkDay]),
                                                    DATESBETWEEN(RollingDate[Date],
                                                    Invoices[PickedDate],
                                                    Invoices[DeliveryDate])) + 0)

Thank you!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.