Forum Discussion
adding end date
- 2 years ago
Hi evadung ,
How about this:
I did something similar that you suggested: Group By Item with MAX on date and then joined that outcome with the original table. Rest was just some cleansing.
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtMzNNAzMjAyVtJRcgRiIwMQy0IpVidayULP0BBTzhwsZ6xnBpNyAkuZAklTsJQ5kjaEHNDIWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [date = _t, item = _t, warehouse = _t, quantity = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type date}, {"item", type text}, {"warehouse", Int64.Type}, {"quantity", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"item"}, {{"MaxDate", each List.Max([date]), type nullable date}}), #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"item"}, #"Grouped Rows", {"item"}, "Grouped Rows", JoinKind.LeftOuter), #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"MaxDate"}, {"Grouped Rows.MaxDate"}), #"Added Custom" = Table.AddColumn(#"Expanded Grouped Rows", "end date", each if [date] = [Grouped Rows.MaxDate] then null else [Grouped Rows.MaxDate]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Grouped Rows.MaxDate"}) in #"Removed Columns"[Edit]: You might need to add Warehouse to the GROUP BY as well...
Let me know if this solves your query 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/
Hi evadung ,
How about this:
I did something similar that you suggested: Group By Item with MAX on date and then joined that outcome with the original table. Rest was just some cleansing.
Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtMzNNAzMjAyVtJRcgRiIwMQy0IpVidayULP0BBTzhwsZ6xnBpNyAkuZAklTsJQ5kjaEHNDIWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [date = _t, item = _t, warehouse = _t, quantity = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"date", type date}, {"item", type text}, {"warehouse", Int64.Type}, {"quantity", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"item"}, {{"MaxDate", each List.Max([date]), type nullable date}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"item"}, #"Grouped Rows", {"item"}, "Grouped Rows", JoinKind.LeftOuter),
#"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"MaxDate"}, {"Grouped Rows.MaxDate"}),
#"Added Custom" = Table.AddColumn(#"Expanded Grouped Rows", "end date", each if [date] = [Grouped Rows.MaxDate] then null else [Grouped Rows.MaxDate]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Grouped Rows.MaxDate"})
in
#"Removed Columns"
[Edit]: You might need to add Warehouse to the GROUP BY as well...
Let me know if this solves your query 🙂
/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/