Forum Discussion
Max date Keeping Ids Fixed
My first time with power query.
In power query I am trying to create a New column where it is only taking the max date per project ID i.e., keeping the Project ID fixed
| ID | Date | Desired_Column |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | Null | 06/04/2023 |
| 234561 | 08/03/2023 | 06/04/2023 |
| 234561 | 05/04/2023 | 06/04/2023 |
| 234561 | 06/04/2023 | 06/04/2023 |
| 234561 | 06/04/2023 | 06/04/2023 |
| 234561 | 06/04/2023 | 06/04/2023 |
Hi Gcsingh149,
Give this a go.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MTUzVNJRAiIDM10DE10jY6VYnVEJ6koYWOgaGINEcSowhYriVGBGEwWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Desired_Column = _t]), ChType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Desired_Column", type date}}), GroupRows = Table.Group(ChType, {"ID"}, {{"t", each List.Transform( [Date], (x)=> List.Max([Date])), type list}}), Expand = Table.ExpandListColumn(GroupRows, "t") in Expandwith this result
I hope this is helpful
- Anonymous3 years ago
Hi Gcsingh149 ,
Please try.List.Max( Table.SelectRows( PreviousStepName, (x) => x[ID] = [ID])[Date] )all steps.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MTUzVNJRUorVGfI8AwtdA2NdI2OEqBFI1FTXwART1Axd1JAI0VgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Max Date", each List.Max( Table.SelectRows( #"Changed Type", (x) => x[ID] = [ID])[Date] )) in #"Added Custom"Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
2 Replies
- m_dekorteResident Rockstar
Hi Gcsingh149,
Give this a go.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MTUzVNJRAiIDM10DE10jY6VYnVEJ6koYWOgaGINEcSowhYriVGBGEwWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t, Desired_Column = _t]), ChType = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Desired_Column", type date}}), GroupRows = Table.Group(ChType, {"ID"}, {{"t", each List.Transform( [Date], (x)=> List.Max([Date])), type list}}), Expand = Table.ExpandListColumn(GroupRows, "t") in Expandwith this result
I hope this is helpful
- AnonymousNot applicable
Hi Gcsingh149 ,
Please try.List.Max( Table.SelectRows( PreviousStepName, (x) => x[ID] = [ID])[Date] )all steps.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjI2MTUzVNJRUorVGfI8AwtdA2NdI2OEqBFI1FTXwART1Axd1JAI0VgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Date = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Max Date", each List.Max( Table.SelectRows( #"Changed Type", (x) => x[ID] = [ID])[Date] )) in #"Added Custom"Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum