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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Mederic
Post Patron
Post Patron

Table not contains

Hello everyone,
How can I get the result in the image below?
I actually have a table with several columns and around 2000 rows.
The problem here is that I'm looking for a word in a group of words or sentences, regardless of the case.

Thanks in advance

Best regards

 

RefColor
AYellow of sun, car in red, Black for night
APink color, yellow is fun, not in Red, Black only
aWhite paper and Black panther
Bgreen, orange juice and grey
cgreen, orange juice and grey
CPink color, maybe yellow, Red  shoes, Black in men
DYellow or Red
dRed and Black style

 

 

Search.png

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

You implied you wanted to hard-code the excludes within the M-Code itself. So perhaps

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZBBDoIwEEWvMum6lxA9gHFjDGFRywCVOkOmJYbb2xYMxpXbn/cmL1PX6qC0uqH3/ALuIMykwRoBRyDYaqi8sSN0LECuH6Jq9KqcHY1g2bNoWFbdBeiyThyzftl1Jr8U0yTzOriIMJkJBQy1GzIZigNKoapE9YKYbrEY6hEes7NY6LSvp+w/0PGn9GmWO269OhcChIExfEJT9hOpqKevv0hGy9qmNWt7eIiLR9U0bw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ref = _t, Color = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref", type text}, {"Color", type text}}),
    
    #"Select by Criteria" = Table.SelectRows(
        #"Changed Type",
        each not List.Contains({"A","D"},[Ref],Comparer.OrdinalIgnoreCase)
             and not List.ContainsAny(Splitter.SplitTextByAnyDelimiter({" ",","})
                    ([Color]),{"pink","yellow"},Comparer.OrdinalIgnoreCase)
                
    )
in
    #"Select by Criteria"

View solution in original post

14 REPLIES 14
ronrsnfld
Super User
Super User

You implied you wanted to hard-code the excludes within the M-Code itself. So perhaps

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZBBDoIwEEWvMum6lxA9gHFjDGFRywCVOkOmJYbb2xYMxpXbn/cmL1PX6qC0uqH3/ALuIMykwRoBRyDYaqi8sSN0LECuH6Jq9KqcHY1g2bNoWFbdBeiyThyzftl1Jr8U0yTzOriIMJkJBQy1GzIZigNKoapE9YKYbrEY6hEes7NY6LSvp+w/0PGn9GmWO269OhcChIExfEJT9hOpqKevv0hGy9qmNWt7eIiLR9U0bw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ref = _t, Color = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref", type text}, {"Color", type text}}),
    
    #"Select by Criteria" = Table.SelectRows(
        #"Changed Type",
        each not List.Contains({"A","D"},[Ref],Comparer.OrdinalIgnoreCase)
             and not List.ContainsAny(Splitter.SplitTextByAnyDelimiter({" ",","})
                    ([Color]),{"pink","yellow"},Comparer.OrdinalIgnoreCase)
                
    )
in
    #"Select by Criteria"

Hello @ronrsnfld ,

Thank you for your time,
It's perfect, it works very well 😊,

I'd be interested to see @AlienSx's proposal based on a table of criteria.

I'm going to work on it this evening at home to see if I can adapt his code 😊

Best regards

It is trivial to modify my routine if you want to use a Table as a data source for the filter.

 

Assume we have a table named "Filter" that looks like:

ronrsnfld_0-1722372493922.png

Two small changes in the M-Code to reference the Filter table and relevant column:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZBBDoIwEEWvMum6lxA9gHFjDGFRywCVOkOmJYbb2xYMxpXbn/cmL1PX6qC0uqH3/ALuIMykwRoBRyDYaqi8sSN0LECuH6Jq9KqcHY1g2bNoWFbdBeiyThyzftl1Jr8U0yTzOriIMJkJBQy1GzIZigNKoapE9YKYbrEY6hEes7NY6LSvp+w/0PGn9GmWO269OhcChIExfEJT9hOpqKevv0hGy9qmNWt7eIiLR9U0bw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ref = _t, Color = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref", type text}, {"Color", type text}}),
    
    #"Select by Criteria" = Table.SelectRows(
        #"Changed Type",
        each not List.Contains(Filter[Ref],[Ref],Comparer.OrdinalIgnoreCase)
             and not List.ContainsAny(Splitter.SplitTextByAnyDelimiter({" ",","})
                    ([Color]),Filter[Color],Comparer.OrdinalIgnoreCase)
                
    )
in
    #"Select by Criteria"

 

Hello @ronrsnfld ,

Thank you for this proposal based on a table of criteria, it's perfect.
In my real file I have a few cells with the slash symbol / (see screenshot)
It's very easy to add it to your code and it works very well

Thanks again

Best regards

 

Search_2.png

AlienSx
Super User
Super User

    criteria = List.Buffer(criteria_table[Color]),
    result = Table.SelectRows(
        data_table, 
        (w) => List.PositionOf(
            criteria,
            w[Color],
            Occurrence.First,
            (x, y) => Text.Contains(y, x, Comparer.OrdinalIgnoreCase)
        ) = -1
    )

Hello @AlienSx ,

Thank you very much for your solution,
How can we add a 2nd criteria for the [Ref] AND [Color] columns?

Unless I'm mistaken, there is only one criteria [Color] in your proposal

Thank you in advance

Best regard

yes, my bad. But why AND? You eliminated [Ref = "a", Color = "white paper and black panther"]. Condition must be OR, isn't it? 

@AlienSx 

With the advanced filters, I use the display below, which also works for me
I did a test with this example (see screenshot)
The answer to your question is that the criteria are [Ref] AND [Color].

Best regards

Search.png

 

okay

    refs_list = List.Buffer(criteria_table[Ref]),
    colors_list = List.Buffer(criteria_table[Color]),
    not_contains = (lst, txt) => not List.Contains(lst, txt, (x, y) => Text.Contains(y, x, Comparer.OrdinalIgnoreCase)),
    select = Table.SelectRows(
        data_table, 
        (x) => not_contains(refs_list, x[Ref]) and not_contains(colors_list, x[Color])
    )

 

@AlienSx ,
Great solution too,
If my criteria change over time, I'll have 2 ways of doing that
You all amaze me with your solutions.
Thanks to all

Best regards

Greg_Deckler
Community Champion
Community Champion

@Mederic So like this?

Table = 
  VAR __Color = MAX( 'Criteria Not Contains',[Color] )
  VAR __Result = FILTER( 'Data', NOT( CONTRAINSSTRING( [Color], __Color ) ) )
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hello @Greg_Deckler ,
Thank you for your DAX proposal,
I would like a solution with Power Query even though I also like DAX 😊

Best regards

@Mederic Missed what forum it was in. So are those two tables and you are going to do a join on them or ?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hello @Greg_Deckler ,
Sorry, in the example I put a table of criteria but in reality I'd like to write criteria it in the M code without using a join

Best regards

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors