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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
Employee
Employee

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

3 REPLIES 3
Tom_Y
Helper II
Helper II

Gorgeous and amazing code.

CNENFRNL
Community Champion
Community Champion

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 still way beyond their comprehension!

DAX is simple, but NOT EASY!

mahoneypat
Employee
Employee

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors