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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
SamK428113
Frequent Visitor

Need help calculating time between two dates based on conditions

Hello! New to Power BI and need help. 

 

I'm trying to calculate the time between two dates in point in time based on task name and task status (data sample below) in business days.  I tried creating a measure, but thinking I need to create a calculated column for ABC company. 

 

- A new row is created everytime a new transaction takes place.

- Trying to calculate turn around time in business days between Min Time Stamp of  Task Name - '110 - Attach NPS Packets to Quotes' & Task Status 'Assigned' and Max Time Stamp of Task Name - '510 Generate Customer Package' & Task Status 'Completed'

-Data should show Turn around time between the two dates below for ABC company.  There are many other companies in this data but this is a subset

110 - Attach NPS Packets to Quotes - 4/11/2023 7:43:56AM

510 - Generate Customer Package - 5/8/2023 12:48:13 PM

 

COMPANYNAMEEFFECTIVEDATERFPRESPONSEDUEEXTERNALDATETASKNAMETASKSTATUSTIME_STAMP
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM  4/15/2022 11:18:25 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM50 - Send Renewal Activity NotificationAssigned4/15/2022 11:18:26 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM30 - Evolve Quoting RequestAssigned4/15/2022 11:18:27 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM  4/15/2022 11:18:28 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM40 - Receive Renewal DocumentsAssigned4/15/2022 11:18:27 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM40 - Receive Renewal DocumentsAssigned4/15/2022 11:18:27 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM10 - Initiate Customer Package RequestCompleted4/15/2022 11:18:24 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM  4/15/2022 11:18:26 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM50 - Send Renewal Activity NotificationStarted4/15/2022 11:20:51 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM50 - Send Renewal Activity NotificationCompleted4/15/2022 11:20:58 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM40 - Receive Renewal DocumentsCompleted4/27/2022 12:24:59 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM40 - Receive Renewal DocumentsStarted4/27/2022 12:24:53 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM40 - Receive Renewal DocumentsStarted4/27/2022 12:25:04 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM  4/27/2022 12:25:10 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM40 - Receive Renewal DocumentsCompleted4/27/2022 12:25:10 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM180 - Review QuotesAssigned4/27/2022 2:47:44 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM180 - Review QuotesStarted4/27/2022 2:47:53 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM180 - Review QuotesCompleted4/27/2022 2:48:19 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM30 - Evolve Quoting RequestStarted4/27/2022 2:48:25 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM  4/27/2022 2:48:21 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM30 - Evolve Quoting RequestAssigned4/27/2022 2:48:43 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM510 - Generate Customer PackageAssigned4/27/2022 2:48:44 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM  4/27/2022 2:48:43 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM30 - Evolve Quoting RequestCompleted4/27/2022 2:48:42 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM510 - Generate Customer PackageStarted4/27/2022 2:49:04 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM  4/27/2022 2:50:46 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM510 - Generate Customer PackageCompleted4/27/2022 2:50:46 PM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM30 - Evolve Quoting RequestStarted10/5/2022 10:45:23 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM30 - Evolve Quoting RequestCompleted10/5/2022 10:45:57 AM
ABC1/1/2023 12:00:00 AM5/27/2022 11:15:00 AM  10/5/2022 10:45:58 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM110 - Attach NPS Packets to QuotesStarted4/12/2023 5:55:38 AM
ABC1/1/2024 12:00:00 AM 710 - Update Quoting RequestStarted4/11/2023 7:41:48 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM110 - Attach NPS Packets to QuotesAssigned4/11/2023 7:43:56 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM  4/11/2023 7:43:56 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM  4/11/2023 7:43:53 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM710 - Update Quoting RequestCompleted4/11/2023 7:43:50 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM  4/11/2023 7:43:54 AM
ABC1/1/2024 12:00:00 AM   4/11/2023 7:32:52 AM
ABC1/1/2024 12:00:00 AM 710 - Update Quoting RequestAssigned4/11/2023 7:32:52 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM30 - Evolve Quoting RequestStarted4/13/2023 9:56:22 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM30 - Evolve Quoting RequestCompleted4/13/2023 9:58:29 AM
ABC1/1/2024 12:00:00 AM5/15/2023 7:41:00 AM110 - Attach NPS Packets to QuotesStarted4/13/2023 1:32:31 PM
1 ACCEPTED SOLUTION

Hi @SamK428113 ,

 

From your description, it seems that the "510 task" to be calculated should occur after the "110 assigned", right?

If so, please try:

time between two dates =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[TIME_STAMP] ),
        FILTER (
            ALL ( 'Table' ),
            [COMPANYNAME] = SELECTEDVALUE ( 'Table'[COMPANYNAME] )
                && [TASKNAME] = "110 - Attach NPS Packets to Quotes"
                && [TASKSTATUS] = "Assigned"
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'Table'[TIME_STAMP] ),
        FILTER (
            ALL ( 'Table' ),
            [COMPANYNAME] = SELECTEDVALUE ( 'Table'[COMPANYNAME] )
                && [TASKNAME] = "510 - Generate Customer Package"
                && [TASKSTATUS] = "Completed"
        )
    )
VAR _c =
    IF ( _b > _a, _b )
RETURN
    DATEDIFF ( _c, _a, MINUTE )

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
SamK428113
Frequent Visitor

Hi Jianbo - One additional question.  Instead of calculating calendar days or minutes, is it possible to calculate by networkdays?  

Hi @SamK428113 ,

 

This DAX function may help you:

NETWORKDAYS

You can try to replace DATEDIFF with this fuction.

 

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-jianboli-msft
Community Support
Community Support

Hi @SamK428113 ,

 

Please try:

time between two dates =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[TIME_STAMP] ),
        FILTER (
            ALL ( 'Table' ),
            [COMPANYNAME] = SELECTEDVALUE ( 'Table'[COMPANYNAME] )
                && [TASKNAME] = "110 - Attach NPS Packets to Quotes"
                && [TASKSTATUS] = "Assigned"
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'Table'[TIME_STAMP] ),
        FILTER (
            ALL ( 'Table' ),
            [COMPANYNAME] = SELECTEDVALUE ( 'Table'[COMPANYNAME] )
                && [TASKNAME] = "510 - Generate Customer Package"
                && [TASKSTATUS] = "Completed"
        )
    )
RETURN
    DATEDIFF ( _b, _a, MINUTE )

Final output:

vjianbolimsft_0-1684136393506.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Jianbo - Thank you!  I was able to replicate the calculation and seems to be working.  However, some of these companies are the same but from the previous year.  For this year, some of the companies, after a 110 assigned, but has not completed a 510 task yet.  It seems to be pulling from the 510 from the previous year.  Is there a way to omit the calculation and not pull from last year's 510 for the same company? 

SamK428113_0-1684167774172.png

 

Thank you in advance!

Hi @SamK428113 ,

 

From your description, it seems that the "510 task" to be calculated should occur after the "110 assigned", right?

If so, please try:

time between two dates =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[TIME_STAMP] ),
        FILTER (
            ALL ( 'Table' ),
            [COMPANYNAME] = SELECTEDVALUE ( 'Table'[COMPANYNAME] )
                && [TASKNAME] = "110 - Attach NPS Packets to Quotes"
                && [TASKSTATUS] = "Assigned"
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'Table'[TIME_STAMP] ),
        FILTER (
            ALL ( 'Table' ),
            [COMPANYNAME] = SELECTEDVALUE ( 'Table'[COMPANYNAME] )
                && [TASKNAME] = "510 - Generate Customer Package"
                && [TASKSTATUS] = "Completed"
        )
    )
VAR _c =
    IF ( _b > _a, _b )
RETURN
    DATEDIFF ( _c, _a, MINUTE )

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.