Forum Discussion
Anonymous
6 years agoNot applicable
How to keep rows with the most recent date
Hello, I have an excel table I'm bringing into Power BI. I'm trying to figure out how to keep only the rows with the most recent date (Oil Change Date). Here is an example of the table: ...
- 6 years ago
Hi Anonymous
In edit queries,
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcssvSlHSUTLVt9Q3MjA0UIrViVZy8g0HClnqG4KEjMFCIanFOYlAQUMDfSOwsDlY2DkjtawSrN0UKGhgARaEGmmuD1JsYGiIotLQECJsYIlirjFUMcQEr9TUApBafWOQmCWyqUD9xjBjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Group = _t, #"Oil Change Date" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"Oil Change Date", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Group"}, {"AllRows", each _, type table [Group=text, Oil Change Date=date]}), RankFunction = (tabletorank as table) as table => let SortRows = Table.Sort(tabletorank,{{"Oil Change Date", Order.Descending}}), AddIndex = Table.AddIndexColumn(SortRows, "Rank", 1, 1) in AddIndex, AddedRank = Table.TransformColumns(#"Grouped Rows", {"AllRows", each RankFunction(_)}), #"Expanded AllRows" = Table.ExpandTableColumn(AddedRank, "AllRows", {"Oil Change Date", "Rank"}, {"AllRows.Oil Change Date", "AllRows.Rank"}), #"Filtered Rows" = Table.SelectRows(#"Expanded AllRows", each ([AllRows.Rank] = 1)) in #"Filtered Rows"Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-juanli-msft
Community Support
6 years agoHi Anonymous
In edit queries,
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcssvSlHSUTLVt9Q3MjA0UIrViVZy8g0HClnqG4KEjMFCIanFOYlAQUMDfSOwsDlY2DkjtawSrN0UKGhgARaEGmmuD1JsYGiIotLQECJsYIlirjFUMcQEr9TUApBafWOQmCWyqUD9xjBjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Group = _t, #"Oil Change Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"Oil Change Date", type date}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Group"}, {"AllRows", each _, type table [Group=text, Oil Change Date=date]}),
RankFunction = (tabletorank as table) as table =>
let
SortRows = Table.Sort(tabletorank,{{"Oil Change Date", Order.Descending}}),
AddIndex = Table.AddIndexColumn(SortRows, "Rank", 1, 1)
in
AddIndex,
AddedRank = Table.TransformColumns(#"Grouped Rows", {"AllRows", each RankFunction(_)}),
#"Expanded AllRows" = Table.ExpandTableColumn(AddedRank, "AllRows", {"Oil Change Date", "Rank"}, {"AllRows.Oil Change Date", "AllRows.Rank"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded AllRows", each ([AllRows.Rank] = 1))
in
#"Filtered Rows"
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.