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

Picking highest duration of duplicated values

Hello Power BI Community,

 

Am trying to find a way where I can pick the longest duration associated with duplicated traces in Power Query.

Hope someone could help, I've put some photos for illustration below where highlighted are the values to keep:

 

Mobafa_0-1660619216696.png

Thank you in advance,

Mobafa

1 ACCEPTED SOLUTION

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Trace", Int64.Type}, {"Target Action", type text}, {"Account Type", type text}, {"Date", type datetime}, {"Duration", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Trace"}, {{"Count", each Table.Max(_,"Duration")}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"Target Action", "Account Type", "Date", "Duration"}, {"Target Action", "Account Type", "Date", "Duration"})
in
    #"Expanded Count"

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

10 REPLIES 10
Anonymous
Not applicable

Thank you Sir, this worked. Had to do some spin to my coding and it finally got to the results am looking for 🙂 

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
MahyarTF
Memorable Member
Memorable Member

In Power Query use the 'Group By' in Home tab and select the 'Trace' column in first column and 'Max' in Operation, the 'Duration' column in column drop-down list :

MahyarTF_0-1660621308563.png

Select Ok

MahyarTF_1-1660621331908.png

Appreciate to Kudos

Mahyartf
Anonymous
Not applicable

Hi MahyarTF,

 

Problem is, I have multiple columns other than those two. When this is done the other columns disappear.

 

Thanks,

Mobafa

Hi,

Not sure what is your business and how you want to use the max duration,

But you could create a duplicated table (just on the 'Trace' and 'Duration' Column), and do the Group by on this copy table, then use the MaxDuration based on the Trace number in your visuals.

Again, not sure if it is useful for you.

 

Appreciate for Kudos.

Mahyartf
Ashish_Mathur
Super User
Super User

Hi,

You can use the Table.Max() "M" language function.  To get mre help, share data in an MS Excel formatted table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hello Ashish,

 

Tried to attach a file sample for you to review but I guess it is not supported.

 

Could you advise of other possible methods to share? 

 

Thank you,

Mobafa

Hi,

Upload the file to Google Drive/One Drive and share the download link here.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi Ashish,

 

Here you go, file is uploaded to the below link:

 

https://www.dropbox.com/s/9n40tjvlqtkh0f0/Sample%20Data.csv?dl=0

 

Thank you,

Mobafa

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Trace", Int64.Type}, {"Target Action", type text}, {"Account Type", type text}, {"Date", type datetime}, {"Duration", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Trace"}, {{"Count", each Table.Max(_,"Duration")}}),
    #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"Target Action", "Account Type", "Date", "Duration"}, {"Target Action", "Account Type", "Date", "Duration"})
in
    #"Expanded Count"

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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