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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
yashponde
New Member

Calculate number of working days between two date columns

Hi guys,

 

I need to calculate the number of days a case was delayed. I have 2 date columns in my main table 'Resolution Date' and 'Resolution Due By'.

 

I have created a column in the date table which mentions if it is a working day or no.

 

I need to create a column that calculated the delay (working days only) with the following logic:

 

if(resolution date = blank(), if(today()>resolution due by,(today()-resolution due by),0),(resolution date-resolution due date))

 

yashponde_0-1617145497511.png

 

 

 

 

1 ACCEPTED SOLUTION
bongmw
Helper I
Helper I

Just reread your question, and tweaked the DAX a little so that it substitutes any blank in Resolution Date with the current date, and then works out the delay. One important thing to point out is that you will need to have your date table up to the current date or the DAX will return an error of "An invalid numeric representation of a date value was encountered"

 

 

=
VAR ResolutionDate = IF(ISBLANK(Resolution[Resolution Date]),TODAY(),Resolution[Resolution Date])
RETURN
IF (
ResolutionDate > Resolution[Resolution Due By],
CALCULATE (
COUNTROWS ( 'Date' ),
DATESBETWEEN (
'Date'[Date],
Resolution[Resolution Due By],
ResolutionDate - 1
),
'Date'[IsWorkingDay] = 1,
ALL ( Resolution )
),
- CALCULATE (
COUNTROWS ( 'Date' ),
DATESBETWEEN (
'Date'[Date],
ResolutionDate ,
Resolution[Resolution Due By] - 1
),
'Date'[IsWorkingDay] = 1,
ALL ( Resolution )
)
)

View solution in original post

5 REPLIES 5
bongmw
Helper I
Helper I

Just reread your question, and tweaked the DAX a little so that it substitutes any blank in Resolution Date with the current date, and then works out the delay. One important thing to point out is that you will need to have your date table up to the current date or the DAX will return an error of "An invalid numeric representation of a date value was encountered"

 

 

=
VAR ResolutionDate = IF(ISBLANK(Resolution[Resolution Date]),TODAY(),Resolution[Resolution Date])
RETURN
IF (
ResolutionDate > Resolution[Resolution Due By],
CALCULATE (
COUNTROWS ( 'Date' ),
DATESBETWEEN (
'Date'[Date],
Resolution[Resolution Due By],
ResolutionDate - 1
),
'Date'[IsWorkingDay] = 1,
ALL ( Resolution )
),
- CALCULATE (
COUNTROWS ( 'Date' ),
DATESBETWEEN (
'Date'[Date],
ResolutionDate ,
Resolution[Resolution Due By] - 1
),
'Date'[IsWorkingDay] = 1,
ALL ( Resolution )
)
)

This works perfectly fine. Thanks @bongmw 

Jihwan_Kim
Super User
Super User

Hi, @yashponde 

Please correct me if I wrongly understood your question.

I assume today() = selected date from a slicer.

 

Please check the below picture if that is what you are looking for.

The sample pbix file's link is down below, and the measure is in the file as well.

 

Picture1.png

 

https://www.dropbox.com/s/6l7bxkn50mzd6f7/yashponde.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster.

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Hi @Jihwan_Kim 

 

Today refers to the current date (eg:31/03/2021)

bongmw
Helper I
Helper I

Hi @yashponde 

 

You can refer to this link from SQLBI on counting the number of working days.

 

In your case, however there are a few additional logic to take care of - cases where the Resolution Date could be blank, and also cases where Resolution Date is greater than Resolution Due By date, and vice versa.

 

A simple way is just to take care of these with IF statements. A calculated column would be like below. Also note that your date table needs to cover the full range of possible dates in Table1 (which I have named Resolution table in my code below)

 

=IF (
    NOT ISBLANK ( Resolution[Resolution Date] ),
    IF (
        Resolution[Resolution Date] > Resolution[Resolution Due By],
        CALCULATE (
            COUNTROWS ( 'Date' ),
            DATESBETWEEN (
                'Date'[Date],
                Resolution[Resolution Due By],
                Resolution[Resolution Date] - 1
            ),
            'Date'[IsWorkingDay] = 1,
            ALL ( Resolution )
        ),
        CALCULATE (
            COUNTROWS ( 'Date' ),
            DATESBETWEEN (
                'Date'[Date],
                Resolution[Resolution Date],
                Resolution[Resolution Due By] - 1
            ),
            'Date'[IsWorkingDay] = 1,
            ALL ( Resolution )
        )
    )
)

 

Capture.JPG

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.