Forum Discussion
Grouping BY
Hi Guys,
How could I create a new column grouping by ID that brings me the name of the Step (Etapa Column) and the most recent date?
result:
idrepasse: 57468
Etapa: Distrato
CreatedDate: 01/11/2022
kasife you can learn from the following M code, start a new query -> click advanced editor and paste the M code. Use these steps in your data:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjU3NbFQ0lFyySwuKUosyQcyjQyMjHQNDXUNDJVidRAqwlLzUhLh0ga6RqZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [idrepasse = _t, Etapa = _t, CreatedDate = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"idrepasse", Int64.Type}, {"Etapa", type text}, {"CreatedDate", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"idrepasse"}, {{"MaxDate", each List.Max([CreatedDate]), type nullable date}, {"All", each _, type table [idrepasse=nullable number, Etapa=nullable text, CreatedDate=nullable date]}}), #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Etapa", "CreatedDate"}, {"Etapa", "CreatedDate"}), #"Filter Max Date" = Table.SelectRows(#"Expanded All", each [MaxDate] = [CreatedDate]), #"Removed Columns" = Table.RemoveColumns(#"Filter Max Date",{"MaxDate"}) in #"Removed Columns"Follow us on LinkedIn and to our YouTube channel
I would ❤ Kudos if my solution helped. If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
2 Replies
- parry2kSuper User
kasife you can learn from the following M code, start a new query -> click advanced editor and paste the M code. Use these steps in your data:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjU3NbFQ0lFyySwuKUosyQcyjQyMjHQNDXUNDJVidRAqwlLzUhLh0ga6RqZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [idrepasse = _t, Etapa = _t, CreatedDate = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"idrepasse", Int64.Type}, {"Etapa", type text}, {"CreatedDate", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"idrepasse"}, {{"MaxDate", each List.Max([CreatedDate]), type nullable date}, {"All", each _, type table [idrepasse=nullable number, Etapa=nullable text, CreatedDate=nullable date]}}), #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Etapa", "CreatedDate"}, {"Etapa", "CreatedDate"}), #"Filter Max Date" = Table.SelectRows(#"Expanded All", each [MaxDate] = [CreatedDate]), #"Removed Columns" = Table.RemoveColumns(#"Filter Max Date",{"MaxDate"}) in #"Removed Columns"Follow us on LinkedIn and to our YouTube channel
I would ❤ Kudos if my solution helped. If you can spend time posting the question, you can also make effort to give Kudos to whoever helped to solve your problem. It is a token of appreciation!