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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calculated column to get the start and end date time

Hi, We have the below table data. Application ID, Stage no, Status and Date Time.

 

Each applcation will have multiple stages to go and there will be reversals too. In the below table you could see after stage 3 it again came to stage 2 and same happens after stage 4 too.

 

Each set of stage will have a start status and complete status with date and time. If it is not having complete status, then it means it is still in progress. 

 

Application IDStageStatusDate Time
1231Start09-08-2021 12:00
1231Complete09-08-2021 13:00
1232Start09-08-2021 14:00
1232Complete09-08-2021 15:00
1233Start09-08-2021 16:00
1233Complete09-08-2021 17:30
1232Start09-08-2021 18:00
1232Complete09-08-2021 19:30
1233Start09-08-2021 20:00
1233Complete09-08-2021 21:00
1234Start09-08-2021 22:00
1234Complete09-08-2021 22:30
1233Start09-08-2021 23:00

 

I need to frame the above table like below given table.

 

Application IDStageStart Date TimeCompleted Date Time
123109-08-2021 12:0009-08-2021 13:00
123209-08-2021 14:0009-08-2021 15:00
123309-08-2021 16:0009-08-2021 17:30
123209-08-2021 18:0009-08-2021 19:30
123309-08-2021 20:0009-08-2021 21:00
123409-08-2021 22:0009-08-2021 22:30
123309-08-2021 23:00Current Date Time

 

Each set of application and stage should be in same row with start and complete date time. Eventhough the application has duplicate stages in it the Date time fields will always be unique since it is a stage approval process.

 

Please help.

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, I did the following test:

Group =
COUNTX (
    FILTER (
        ALL ( Sheet1 ),
        [Status] = "Start"
            && [DateTime] <= EARLIER ( Sheet1[DateTime] )
            && [Stage] = EARLIER ( Sheet1[Stage] )
    ),
    [Stage]
)
M =
VAR _start =
    CALCULATE (
        MAX ( 'Sheet1'[DateTime] ),
        FILTER (
            ALL ( Sheet1 ),
            [Stage] = MAX ( 'Sheet1'[Stage] )
                && [Group] = MAX ( 'Sheet1'[Group] )
                && [Status] = "Start"
        )
    )
VAR _end =
    CALCULATE (
        MAX ( 'Sheet1'[DateTime] ),
        FILTER (
            ALL ( Sheet1 ),
            [Stage] = MAX ( 'Sheet1'[Stage] )
                && [Group] = MAX ( 'Sheet1'[Group] )
                && [Status] = "Complete"
        )
    )
RETURN
    _start & "-"
        & IF ( _end = BLANK (), NOW (), _end )

vhenrykmstf_0-1631608718933.png


Best Regards,
Henry


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

3 REPLIES 3
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your description, I did the following test:

Group =
COUNTX (
    FILTER (
        ALL ( Sheet1 ),
        [Status] = "Start"
            && [DateTime] <= EARLIER ( Sheet1[DateTime] )
            && [Stage] = EARLIER ( Sheet1[Stage] )
    ),
    [Stage]
)
M =
VAR _start =
    CALCULATE (
        MAX ( 'Sheet1'[DateTime] ),
        FILTER (
            ALL ( Sheet1 ),
            [Stage] = MAX ( 'Sheet1'[Stage] )
                && [Group] = MAX ( 'Sheet1'[Group] )
                && [Status] = "Start"
        )
    )
VAR _end =
    CALCULATE (
        MAX ( 'Sheet1'[DateTime] ),
        FILTER (
            ALL ( Sheet1 ),
            [Stage] = MAX ( 'Sheet1'[Stage] )
                && [Group] = MAX ( 'Sheet1'[Group] )
                && [Status] = "Complete"
        )
    )
RETURN
    _start & "-"
        & IF ( _end = BLANK (), NOW (), _end )

vhenrykmstf_0-1631608718933.png


Best Regards,
Henry


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

amitchandak
Super User
Super User

@Anonymous , based on what I got so far

 

Unpivot last two column power query

https://radacad.com/pivot-and-unpivot-with-power-bi

 

Or create a table in dax

summarize(Table, [Application ID],[Stage], "Start Date", maxx(filter(Table, Table[Status] = "Start" ),[Date Time]), "End Date", maxx(filter(Table, Table[Status] = "Complete" ),[Date Time]))

 

or used the last column in above table as measures in a visual

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak  This DAX does not works...it excludes the duplicate stages.

 

Check this sample PBIX - https://1drv.ms/u/s!Ah-kO6CqeTNOgkHMByZiYJXGaeSO?e=Y4cc6r

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors