cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mwaltercpa
Advocate III
Advocate III

Remove rows based on column values that contain keywords from a list/table.

I would like to feed my query a list of key words i.e. "Store Acct" and "Do Not Use", and eliminate the rows in my table where those key words occur within the column [Rep Name].

mwaltercpa_1-1637013856409.png

Rather than go through the filter column advanced editor and key in every 'and' condition, I'd like to just maintain a list of keywords (see query below), then use that list to filter through my [Rep Name] column. Is this possible? The below query works only when I include a listing of the entire contents of the field to remove. - Many thanks!

 

mwaltercpa_0-1637013166323.png

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft
Microsoft

Here's one way to do it in the query editor with a custom filter expression.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi7JL0pVcExOLlHwz0tVitVBEQopzwcLueQr+OWXKIQWp8JVIQnBVHnlQ6R8E4sqlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Rep Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Rep Name", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each let thisrep = [Rep Name] in List.Count(List.Select({"Do Not Use", "Store Acct"}, each Text.Contains(thisrep, _))) = 0)
in
    #"Filtered Rows"

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
CNENFRNL
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi7JL0pVcExOLlHwz0tVitVBEQopzwcLueQr+OWXKIQWp8JVIQnBVHnlQ6R8E4sqlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Rep Name" = _t]),
    #"List of Keywords" = {"Do Not Use", "Store Acct"},
    #"Selected Rows" = Table.SelectRows(Source, each not List.Accumulate(#"List of Keywords", false, (s,c) => s or Text.Contains([Rep Name], c, Comparer.OrdinalIgnoreCase)))
in
    #"Selected Rows"

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is beyond their comprehension!

DAX is simple, but NOT EASY!

mahoneypat
Microsoft
Microsoft

Here's one way to do it in the query editor with a custom filter expression.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCi7JL0pVcExOLlHwz0tVitVBEQopzwcLueQr+OWXKIQWp8JVIQnBVHnlQ6R8E4sqlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Rep Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Rep Name", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each let thisrep = [Rep Name] in List.Count(List.Select({"Do Not Use", "Store Acct"}, each Text.Contains(thisrep, _))) = 0)
in
    #"Filtered Rows"

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors