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
Anonymous
Not applicable

DATEDIFF between two tasks in same column

Hello,

 

I am fairly new to Power BI and DAX. I am trying to get a DATEDIFF between two tasks within the same column. There are other tasks in the workflow besides what I want to calculate. I was able to create a calculated column (Rework_Start_Finish) to get just the dates to calculate the rework times. The rework time needs to be calculated using the difference between the start time of the Rework Task and the start time of the Submit for Approval Task. The issue I am having is how to write the DAX to get the date difference.

 

Here is example data for 2 workflows from the Work_Item table. I have many thousands of them in the database that will need to be calculated

 

Workflow_IDTaskTask Start DateRework_Start_Finish
1Submit for Approval12/2/2021 14:23 
1Process12/2/2021 15:06 
1Rework12/2/2021 15:3212/2/2021 15:32
1Submit for Approval12/2/2021 16:4912/2/2021 16:49
1Process12/2/2021 16:49 
1Review12/2/2021 16:52 
1Rework4/8/2022 18:204/8/2022 18:20
1Submit for Approval5/5/2022 13:435/5/2022 13:43
1Process5/6/2022 14:22 
1Rework5/6/2022 14:345/6/2022 14:34
1Submit for Approval5/6/2022 14:545/6/2022 14:54
1Process5/6/2022 14:55 
1Review5/6/2022 15:23 
1Rework6/3/2022 13:316/3/2022 13:31
1Submit for Approval6/9/2022 19:446/9/2022 19:44
1Process6/9/2022 19:51 
1Review6/9/2022 20:23 
1Rework6/17/2022 14:136/17/2022 14:13
1Submit for Approval6/17/2022 15:296/17/2022 15:29
1Process6/17/2022 15:31 
1Rework6/17/2022 15:496/17/2022 15:49
1Submit for Approval6/17/2022 16:496/17/2022 16:49
2Submit for Approval6/23/2022 14:28 
2Submit for Approval6/23/2022 14:59 
2Rework7/25/2022 21:587/25/2022 21:58
2Submit for Approval8/2/2022 14:088/2/2022 14:08
2Process8/2/2022 14:12 
2Rework8/2/2022 14:458/2/2022 14:45
2Submit for Approval8/2/2022 15:488/2/2022 15:48
2Process8/2/2022 15:51 
2Review8/2/2022 16:03 
2Rework8/3/2022 14:118/3/2022 14:11
2Submit for Approval8/3/2022 14:598/3/2022 14:59
2Process8/3/2022 15:03 
2Review8/3/2022 15:05 

 

Here is the expected result after the DAX for the Rework Time in Minutes column

 

Workflow_IDTaskTask Start DateRework_Start_FinishRework Time in Minutes
1Submit for Approval12/2/2021 14:23  
1Process12/2/2021 15:06  
1Rework12/2/2021 15:3212/2/2021 15:32 
1Submit for Approval12/2/2021 16:4912/2/2021 16:4976
1Process12/2/2021 16:49  
1Review12/2/2021 16:52  
1Rework4/8/2022 18:204/8/2022 18:20 
1Submit for Approval5/5/2022 13:435/5/2022 13:4338603
1Process5/6/2022 14:22  
1Rework5/6/2022 14:345/6/2022 14:34 
1Submit for Approval5/6/2022 14:545/6/2022 14:5420
1Process5/6/2022 14:55  
1Review5/6/2022 15:23  
1Rework6/3/2022 13:316/3/2022 13:31 
1Submit for Approval6/9/2022 19:446/9/2022 19:449014
1Process6/9/2022 19:51  
1Review6/9/2022 20:23  
1Rework6/17/2022 14:136/17/2022 14:13 
1Submit for Approval6/17/2022 15:296/17/2022 15:2976
1Process6/17/2022 15:31  
1Rework6/17/2022 15:496/17/2022 15:49 
1Submit for Approval6/17/2022 16:496/17/2022 16:4960
2Submit for Approval6/23/2022 14:28  
2Submit for Approval6/23/2022 14:59  
2Rework7/25/2022 21:587/25/2022 21:58 
2Submit for Approval8/2/2022 14:088/2/2022 14:0811049
2Process8/2/2022 14:12  
2Rework8/2/2022 14:458/2/2022 14:45 
2Submit for Approval8/2/2022 15:488/2/2022 15:4862
2Process8/2/2022 15:51  
2Review8/2/2022 16:03  
2Rework8/3/2022 14:118/3/2022 14:11 
2Submit for Approval8/3/2022 14:598/3/2022 14:5948
2Process8/3/2022 15:03  
2Review8/3/2022 15:05  

 

Here is the DAX I used to get the Rework_Start_Finish calculated column in the Work_Item:

 

 

 

Rework_Start_Finish =
VAR First_Rework_Task =
    CALCULATE (
        MINX ( Work_Item, Work_Item[WORK_CREATE] ),
        ALLEXCEPT ( Work_Item, Work_Item[Workflow_ID] ),
        Work_Item[TASK] = "Rework"
    )
RETURN
    IF (
        Work_Item[TASK] = "Rework"
            || Work_Item[TASK] = "Submit for Approval"
                && NOT ( ISBLANK ( First_Rework_Task ) )
                    && First_Rework_Task <= Work_Item[WORK_CREATE],
        Work_Item[WORK_CREATE]
    )

 

 

 

 
I would appreciate any help that anyone can provide me.
 
Thanks,
Dennis_W
 
1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Anonymous 

try to write the column like this:

ReworkInMinutes = 
VAR _date = [Task Start Date] 
VAR _id = [Workflow_ID]
VAR _reworkdate = 
MAXX(
    FILTER(
        TableName,
        TableName[Task Start Date] <_date
            &&TableName[Workflow_ID] = _id
            &&TableName[Task] = "Rework"
    ),
    TableName[Task Start Date]
)
RETURN
IF(
    [Task]="Submit for Approval",
    DATEDIFF(_reworkdate, _date, MINUTE),
    BLANK()
)

 

it worked like this:

FreemanZ_0-1673941212152.png

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @Anonymous 

try to write the column like this:

ReworkInMinutes = 
VAR _date = [Task Start Date] 
VAR _id = [Workflow_ID]
VAR _reworkdate = 
MAXX(
    FILTER(
        TableName,
        TableName[Task Start Date] <_date
            &&TableName[Workflow_ID] = _id
            &&TableName[Task] = "Rework"
    ),
    TableName[Task Start Date]
)
RETURN
IF(
    [Task]="Submit for Approval",
    DATEDIFF(_reworkdate, _date, MINUTE),
    BLANK()
)

 

it worked like this:

FreemanZ_0-1673941212152.png

Anonymous
Not applicable

Thank you!! That worked.

 

Dennis_W

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.