Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
antalgu
Helper I
Helper I

Remove rows by a Criteria

I'm pretty new to the M language of Power Query. I'm working with a table that has phone calls and information about each one of them, for what we want it that table could be summarized as this table:

CampaignCall duration
A10
A20
B10

I want to eliminate the calls that have a duration < 15 and are of campaign A, so the resulting table would look like this:

CampaignCall duration
A20
B10

So what I really wanna do is eliminate columns based on a criteria, I didn't seem to find any function capable of doing that at first glance, but I suspect it could be done using the function Table.RemoveMatchingRows, but I don't know how.

1 ACCEPTED SOLUTION
edhans
Community Champion
Community Champion

You want Table.SelectRows. Start by removing all rows that are 15 or lower.

edhans_0-1601653202902.png

That generates this statement. It is wrong, but Power Query has generated most of what we need.

= Table.SelectRows(#"Changed Type", each [Call duration] <= 15)

Now manually modify that to be this:

= Table.SelectRows(#"Changed Type", each not ([Call duration] <= 15 and [Campaign] = "A"))

That returns this:

edhans_1-1601653387021.png

So what I told it is select any records with call durations that are less than 15 and  are of Campaign A. That is this part:

([Call duration] <= 15 and [Campaign] = "A")

Since that is the exact opposite of what I really want, I put a "not" in front if it.

 

Make sense? Full code here:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0UIrVgTCNIEwnqGgsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Campaign = _t, #"Call duration" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Campaign", type text}, {"Call duration", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each not ([Call duration] <= 15 and [Campaign] = "A"))
in
    #"Filtered Rows"

 

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.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Community Champion
Community Champion

You want Table.SelectRows. Start by removing all rows that are 15 or lower.

edhans_0-1601653202902.png

That generates this statement. It is wrong, but Power Query has generated most of what we need.

= Table.SelectRows(#"Changed Type", each [Call duration] <= 15)

Now manually modify that to be this:

= Table.SelectRows(#"Changed Type", each not ([Call duration] <= 15 and [Campaign] = "A"))

That returns this:

edhans_1-1601653387021.png

So what I told it is select any records with call durations that are less than 15 and  are of Campaign A. That is this part:

([Call duration] <= 15 and [Campaign] = "A")

Since that is the exact opposite of what I really want, I put a "not" in front if it.

 

Make sense? Full code here:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0UIrVgTCNIEwnqGgsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Campaign = _t, #"Call duration" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Campaign", type text}, {"Call duration", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each not ([Call duration] <= 15 and [Campaign] = "A"))
in
    #"Filtered Rows"

 

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.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.