How to Remove Filtered Rows in Power Query

earthworm

Well-known Member
Joined
May 19, 2009
Messages
773
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I have a data of 1.2 Million. and there are many steps I need to perform in power query based on multiple criteria in multiple columns.
What i want to do is to remove filtered rows based on my requirement for each column using filter so that once all my data is removed i can then close and load to / or create connection.
I need to shape data just like we do in excel by removing all the unnecessary rows and once the data is read I need to create connection only since data length is huge.

How can i remove data based on multiple criteria in single column and multiple criteria in multiple columns just like we do it in excel . This time data is huge and i need to do it in power query
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Sample data showing a before and after will help tremendously. show your data using XL2BB. No pictures as we cannot manipulate data in a picture.
 
Upvote 0
Sample data showing a before and after will help tremendously. show your data using XL2BB. No pictures as we cannot manipulate data in a picture.
Sample Data

Book1
ABCDE
1ABCDE
21D3FFAIL
32F333
43G34
54G325
65H3DSFAIL
76FAILFAILFAIL
8GHFAILFAIL
9FAILFAILFAILFAILD
10FAIL3FAILFAILFAIL
11G3FAILFAIL3
Sheet1


Result

Book1
ABCDE
14ABCDE
152F33FS
163G3FS
174G32
Sheet1


Please note that FAIL is just mentioned as a sample . The Fail term can be dynamic based on human judgement which i will manage manually depending on my choice . The whole row will be deleted based on my filter criteria.
 
Upvote 0
I don't understand your filter criteria. How does the FS come into play? Please explain your thought process so that we can better understand.
 
Upvote 0
I don't understand your filter criteria. How does the FS come into play? Please explain your thought process so that we can better understand.
FS can be any value its just a demo . My main focus is FAIL . Anything that contains FAIL in any column i will remove that entire row in power query.
 
Upvote 0
Alan may have a better way but see if this works for you.
It relies on merging the columns with a "|" separator.
Upper casing it
Adding a "|" to the front
Filtering out any rows with the "|FAIL" in the merged column field.

Currently assumes the starting point is a Table called "Table1" (I prefer to have meaningful table names)

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddColumnMergeCols = Table.AddColumn(Source, "MergedColumn", each Text.Combine(List.Transform(List.Skip(Record.FieldValues(_)),Text.From),"|")),
    #"Uppercased Text" = Table.TransformColumns(AddColumnMergeCols,{{"MergedColumn", Text.Upper, type text}}),
    #"Added Prefix" = Table.TransformColumns(#"Uppercased Text", {{"MergedColumn", each "|" & _, type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Added Prefix", each not Text.Contains([MergedColumn], "|FAIL")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"MergedColumn"})
in
    #"Removed Columns"
 
Upvote 0
Alan may have a better way but see if this works for you.
It relies on merging the columns with a "|" separator.
Upper casing it
Adding a "|" to the front
Filtering out any rows with the "|FAIL" in the merged column field.

Currently assumes the starting point is a Table called "Table1" (I prefer to have meaningful table names)

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddColumnMergeCols = Table.AddColumn(Source, "MergedColumn", each Text.Combine(List.Transform(List.Skip(Record.FieldValues(_)),Text.From),"|")),
    #"Uppercased Text" = Table.TransformColumns(AddColumnMergeCols,{{"MergedColumn", Text.Upper, type text}}),
    #"Added Prefix" = Table.TransformColumns(#"Uppercased Text", {{"MergedColumn", each "|" & _, type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Added Prefix", each not Text.Contains([MergedColumn], "|FAIL")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"MergedColumn"})
in
    #"Removed Columns"
Is there any another approach ? I need to perform in real time based on filter values that can be fail or any other depending on my choice.
 
Upvote 0
You might need to give us more details on a realistic scenario. It sounds like the scenario in your post#3 is too simplistic.
The code I gave you works for that scenario.
 
Upvote 0
Similar approach that Alex took.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(Source, {{"A", type text}, {"B", type text}, {"C", type text}, {"D", type text}, {"E", type text}}, "en-US"),{"A", "B", "C", "D", "E"},Combiner.CombineTextByDelimiter(":", QuoteStyle.None),"Merged"),
    #"Added Custom" = Table.AddColumn(#"Merged Columns", "Custom", each if Text.Contains([Merged],"FAIL") then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 0)),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Filtered Rows", "Merged", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Merged.1", "Merged.2", "Merged.3", "Merged.4", "Merged.5"}),
    #"Removed Columns" = Table.RemoveColumns(#"Split Column by Delimiter",{"Custom"})
in
    #"Removed Columns"
 
Upvote 0
@alansidman, it took quite a while to find a working version of merging columns based on the columns being dynamic. If you don't already have M code tucked away to do that you might want to take a look at my 2nd line.
 
Upvote 0

Forum statistics

Threads
1,223,978
Messages
6,175,754
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top