This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
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 ;). |
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.