Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi Folks,
I'm trying to filter every 3 last months > 0.
e.g.:
The last three months to "DEF" was 0. I need to remove it from my table.
Any ideias?
Ty guys!!
Solved! Go to Solution.
Try this code @Anonymous
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc49DoAgDIbhu3QmKVAjOKr4dwbC/a8hoUvN5/INz/C2tVJiCRx9DORo3fa+npqrlMHj8IXFf12G2045zt+OdduxbjvX/fTN0FFP0FHXzgx/TuB6F1073dsL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Attribute = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Prev3Mo", each Date.IsInPreviousNMonths([Date],3)),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Attribute", "Prev3Mo"}, {{"Total", each List.Sum([Value]), type nullable number}, {"All Rows", each _, type table [Date=nullable date, Attribute=nullable text, Value=nullable number, Prev3Mo=logical]}}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Total] <> 0)),
#"Expanded All Rows" = Table.ExpandTableColumn(#"Filtered Rows", "All Rows", {"Date", "Value"}, {"Date", "Value"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded All Rows",{"Total", "Prev3Mo"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Date", "Attribute", "Value"})
in
#"Reordered Columns"
It turns this:
into this
What I did is this:
How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingTry this code @Anonymous
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc49DoAgDIbhu3QmKVAjOKr4dwbC/a8hoUvN5/INz/C2tVJiCRx9DORo3fa+npqrlMHj8IXFf12G2045zt+OdduxbjvX/fTN0FFP0FHXzgx/TuB6F1073dsL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Attribute = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Value", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Prev3Mo", each Date.IsInPreviousNMonths([Date],3)),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Attribute", "Prev3Mo"}, {{"Total", each List.Sum([Value]), type nullable number}, {"All Rows", each _, type table [Date=nullable date, Attribute=nullable text, Value=nullable number, Prev3Mo=logical]}}),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([Total] <> 0)),
#"Expanded All Rows" = Table.ExpandTableColumn(#"Filtered Rows", "All Rows", {"Date", "Value"}, {"Date", "Value"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded All Rows",{"Total", "Prev3Mo"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Date", "Attribute", "Value"})
in
#"Reordered Columns"
It turns this:
into this
What I did is this:
How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingShould be simple enough.
Got any sample data (not a screenshot)?
And perhaps your current M code from your queries?
| Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 7 | |
| 6 |