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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
cottrera
Post Prodigy
Post Prodigy

Transform table to show minimum time

Hi I have atable like the example below. I would like to perform a tranformation the diplays only the minimum start time for each operative# for each date.

Operative#Activity DateActivity TypeStart Time
301603/10/2022TRAVEL07:51:00
301603/10/2022TRAVEL09:14:03
301603/10/2022WORKING09:40:58
301603/10/2022TRAVEL11:38:27
301604/10/2022TRAVEL07:39:00
301604/10/2022WORKING09:01:00
301604/10/2022COLLECTING10:46:00
301604/10/2022TRAVEL11:41:28
301604/10/2022TRAVEL14:08:24
301604/10/2022WORKING14:23:33
301605/10/2022WORKING09:03:00
301605/10/2022TRAVEL10:04:44
301605/10/2022WORKING10:29:22
301605/10/2022WORKING11:26:11
40348706/10/2022TRAVEL10:20:02
40348706/10/2022WORKING10:58:06
40348706/10/2022TRAVEL12:31:53
40348706/10/2022WORKING13:12:46
40348707/10/2022TRAINING08:00:00
40348707/10/2022TRAVEL10:11:18
40348707/10/2022WORKING10:45:15
40348707/10/2022WORKING13:07:34
40348707/10/2022TRAVEL13:07:49
40348710/10/2022TRAVEL07:03:26
40348710/10/2022WORKING08:00:07
40348710/10/2022TRAVEL08:22:09

 

I would like the end result to look like this

Operative#Activity DateActivity TypeStart Time
301603/10/2022TRAVEL07:51:00
301604/10/2022TRAVEL07:39:00
301605/10/2022WORKING09:03:00
40348706/10/2022TRAVEL10:20:02
40348707/10/2022TRAINING08:00:00
40348710/10/2022TRAVEL07:03:26

 

regards

 

Richard

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @cottrera ,

 

Paste this into a new blank query to see the steps I took:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZPLisJAEEX/JWvBevUjdycig0xQENGF+P+/YWlmhnTGjr1Mc7h96nblduuUOHarjnTNtBYS8Y/zaXPZDc/ThMAg6u6rT2QPNpBWyevx9L0/fI2oEUL+HMoMzZBUkFYR1X4uarXr6d9MU3R7HIbd9jzSTLC4RE9ljSG5gfSifCxrkHVUFFrWGqpz6dw0vL2fQAazhlBHpYcfNqA+fATzCzVSy+kJx4qBuIQssIVDyKDYFCxQRtC2YIXzNg9OZfD+8NOvO9Bvv1X6bz6vg/MCW8xnARzaYH9i33Vrsnix1pesg+9/IN8eiQvsZNXGKlJTsG+6gFzi/gA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Operative#" = _t, #"Activity Date" = _t, #"Activity Type" = _t, #"Start Time" = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Operative#", Int64.Type}, {"Activity Date", type date}, {"Activity Type", type text}, {"Start Time", type time}}),
    groupAllRows = Table.Group(chgTypes, {"Operative#", "Activity Date"}, {{"data", each _, type table [#"Operative#"=nullable number, Activity Date=nullable date, Activity Type=nullable text, Start Time=nullable time]}}),
    addMinStart = Table.AddColumn(groupAllRows, "Custom", each Table.Min([data], "Start Time")),
    expandMinStartRecord = Table.ExpandRecordColumn(addMinStart, "Custom", {"Activity Type", "Start Time"}, {"Activity Type", "Start Time"}),
    remOthCols = Table.SelectColumns(expandMinStartRecord,{"Operative#", "Activity Date", "Activity Type", "Start Time"})
in
    remOthCols

 

Summary:

1) groupAllRows = Group table on [Operative] and [Activity Date], and use the 'All Rows' operator for the aggregation column.

2) addMinStart = Add a new column using Table.Min to pick out the rows from the nested tables that have the lowest [Start Time].

3) expandMinStartRecord = Expand the new record column to reinstate the the columns you want to the main table.

 

Output:

BA_Pete_0-1666268570881.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
cottrera
Post Prodigy
Post Prodigy

Thank you for your quick response the code works fine👍

BA_Pete
Super User
Super User

Hi @cottrera ,

 

Paste this into a new blank query to see the steps I took:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZPLisJAEEX/JWvBevUjdycig0xQENGF+P+/YWlmhnTGjr1Mc7h96nblduuUOHarjnTNtBYS8Y/zaXPZDc/ThMAg6u6rT2QPNpBWyevx9L0/fI2oEUL+HMoMzZBUkFYR1X4uarXr6d9MU3R7HIbd9jzSTLC4RE9ljSG5gfSifCxrkHVUFFrWGqpz6dw0vL2fQAazhlBHpYcfNqA+fATzCzVSy+kJx4qBuIQssIVDyKDYFCxQRtC2YIXzNg9OZfD+8NOvO9Bvv1X6bz6vg/MCW8xnARzaYH9i33Vrsnix1pesg+9/IN8eiQvsZNXGKlJTsG+6gFzi/gA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Operative#" = _t, #"Activity Date" = _t, #"Activity Type" = _t, #"Start Time" = _t]),
    chgTypes = Table.TransformColumnTypes(Source,{{"Operative#", Int64.Type}, {"Activity Date", type date}, {"Activity Type", type text}, {"Start Time", type time}}),
    groupAllRows = Table.Group(chgTypes, {"Operative#", "Activity Date"}, {{"data", each _, type table [#"Operative#"=nullable number, Activity Date=nullable date, Activity Type=nullable text, Start Time=nullable time]}}),
    addMinStart = Table.AddColumn(groupAllRows, "Custom", each Table.Min([data], "Start Time")),
    expandMinStartRecord = Table.ExpandRecordColumn(addMinStart, "Custom", {"Activity Type", "Start Time"}, {"Activity Type", "Start Time"}),
    remOthCols = Table.SelectColumns(expandMinStartRecord,{"Operative#", "Activity Date", "Activity Type", "Start Time"})
in
    remOthCols

 

Summary:

1) groupAllRows = Group table on [Operative] and [Activity Date], and use the 'All Rows' operator for the aggregation column.

2) addMinStart = Add a new column using Table.Min to pick out the rows from the nested tables that have the lowest [Start Time].

3) expandMinStartRecord = Expand the new record column to reinstate the the columns you want to the main table.

 

Output:

BA_Pete_0-1666268570881.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.