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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
DRossi
Helper III
Helper III

Calculated column to show duration of unique ID

Hello,

 

I need some help calculating a duration of a job ID only for one unique ID.

 

Current

This is what I have currently. Each ID returns a duration in the calculated column.

IDStart timeEnd timeDuration
11108:00:0009:30:0001:30:00
11108:00:0009:30:0001:30:00
23410:30:0011:00:0000:30:00
23410:30:0011:00:0000:30:00
23410:30:0011:00:0000:30:00
23410:30:0011:00:0000:30:00

 

Required

This is what is requred. Each unique ID returns only one duration in the calculated column.

IDStart timeEnd timeDuration
11108:00:0009:30:0001:30:00
11108:00:0009:30:00 
23410:30:0011:00:0000:30:00
23410:30:0011:00:00 
23410:30:0011:00:00 
23410:30:0011:00:00 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @DRossi ,

 

First, create a index column in the Power Query.

Screenshot 2021-02-10 152926.png

 

Second, create the calculated column.

Duration = 
VAR tt =
    RANKX (
        FILTER ( 'Table', 'Table'[ID] = EARLIER ( 'Table'[ID] ) ),
        [Index],
        ,
        ASC,
        DENSE
    )
RETURN
    IF ( tt = 1, [End time] - [Start time] )

Screenshot 2021-02-10 153133.png

 

You can check more details from here.

 

Best Regards,

Stephen Tao

 

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

6 REPLIES 6
Anonymous
Not applicable

Hi @DRossi ,

 

First, create a index column in the Power Query.

Screenshot 2021-02-10 152926.png

 

Second, create the calculated column.

Duration = 
VAR tt =
    RANKX (
        FILTER ( 'Table', 'Table'[ID] = EARLIER ( 'Table'[ID] ) ),
        [Index],
        ,
        ASC,
        DENSE
    )
RETURN
    IF ( tt = 1, [End time] - [Start time] )

Screenshot 2021-02-10 153133.png

 

You can check more details from here.

 

Best Regards,

Stephen Tao

 

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

Smashed it @Anonymous  thanks so much.

Tahreem24
Super User
Super User

@DRossi ,

If you ingest your data into power BI so it will automatically show only unique records. Just create Calculated Column like below:

Diff = Table[End time]-Table[Start time]
Capture.PNG
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Hi @Tahreem24 , Unfortuantely it isn't as simple as that. The other rows and columns within the ID hold important information that I haven't shown.

 

I did attempt using this from a similar thread but struggled to modify:

 

Solved: Indexing rows by a distinct values and then gettin... - Microsoft Power BI Community

@DRossi ,

I provided the solution based on the info you have shared. You should have shared in your post regarding more fields as a dummy entry.

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Apologies for that @Tahreem24 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.