Forum Discussion
Anonymous
5 years agoNot applicable
Powerquery filter only most recent data rows
Hi, In a referenced table in PowerQuery I need to work only with latest data from the original table based on column YearMonth (format 202011, 202010, etc). So far we were manually copying newest...
- 5 years ago
Hi Anonymous ,
Try this:
Method1:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtA3NNQ3VNJRMlSK1UGIGAFFjJBEDMBqjFFEQGpMECKWYCWmyAIgFWZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Value = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.IsInCurrentMonth([Date])), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = true)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}) in #"Removed Columns"Method2:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtA3NNQ3VNJRMlSK1UGIGAFFjJBEDMBqjFFEQGpMECKWYCWmyAIgFWZQAUOgvBFYiblSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Value = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each (Date.Year(DateTime.LocalNow())-Date.Year([Date]))*12 + Date.Month(DateTime.LocalNow()) - Date.Month([Date])), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Custom] < Recent_N_Month), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"}) in #"Removed Columns"BTW, .pbix file attached.
Best regards
Icey
If this post helps, then consider Accepting it as the solution to help other members find it faster.
Ashish_Mathur
5 years agoSuper User
Hi,
If you have a new file for each month, then follow the technique shown in the video here - https://www.youtube.com/watch?v=yL11ugShdrk.
Hope this helps.