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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Boricuanet
Frequent Visitor

Delete rows downward

Hi all,

Does anyone know how I can delete all rows down according to data found? Ex: In the column names I search for "Pedro" and if it finds it delete all the rows downwards, is it possible in power query?

 

I am grateful for any suggestions or assistance

1 ACCEPTED SOLUTION
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @Boricuanet,

 

How about this:

Before:

tomfox_0-1650662017366.png

 

 

After:

tomfox_1-1650662053316.png

 

The idea is:

1) create new index column:

tomfox_2-1650662240448.png

 

2) Create new column, find the value "Pedro" and stamp it with 1:

tomfox_3-1650662376363.png

 

 

3) create a running total column:

tomfox_4-1650662505737.png

 

4) Filter for 0 in running total column:

tomfox_5-1650662613980.png

 

 

5) remove all unnecessary columns:

tomfox_6-1650662675950.png

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsnPVYrVAdKJydmVEFZqcgaYUQISKgHy9JJy8tPBQgGpKUX5qJKovBKQcbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if [Column] = "Pedro" then 1 else 0),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Running Total", each List.Sum (List.FirstN(#"Added Custom"[Custom],[Index]))),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Running Total] = 0)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index", "Custom", "Running Total"})
in
    #"Removed Columns"

 

 

 

 

 

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
Boricuanet
Frequent Visitor

Thank you very much, I was unaware of this formula.
At the moment I have an error in "Added" but it must be because of the language.
Thank you very much for your help

Anonymous
Not applicable

You could just add an index column, name that step Table1, then add quick GUI filter for "Pedro", then drill down on the index number, rename that step RowsToKeep. Then add a new step, and use

 

= Table.FirstN(Table1, RowsToKeep)

 

--Nate

tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @Boricuanet,

 

How about this:

Before:

tomfox_0-1650662017366.png

 

 

After:

tomfox_1-1650662053316.png

 

The idea is:

1) create new index column:

tomfox_2-1650662240448.png

 

2) Create new column, find the value "Pedro" and stamp it with 1:

tomfox_3-1650662376363.png

 

 

3) create a running total column:

tomfox_4-1650662505737.png

 

4) Filter for 0 in running total column:

tomfox_5-1650662613980.png

 

 

5) remove all unnecessary columns:

tomfox_6-1650662675950.png

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsnPVYrVAdKJydmVEFZqcgaYUQISKgHy9JJy8tPBQgGpKUX5qJKovBKQcbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each if [Column] = "Pedro" then 1 else 0),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Running Total", each List.Sum (List.FirstN(#"Added Custom"[Custom],[Index]))),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Running Total] = 0)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Index", "Custom", "Running Total"})
in
    #"Removed Columns"

 

 

 

 

 

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

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.