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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
jonclay
Helper IV
Helper IV

Problem with List.Contains

Hi everyone

I have a table of contacts that have various Types attributed to them. For example, the Type could be Type A, AA, AAA, B, BB, BBB etc (this is a multi-select field in my Dynamics CRM).

I've created a Custom Field using the List.Contains function as shown below. What I want is to put a 1 in the Custom Field if the contact record contains AA and AAA and 0 if it doesn't.

if List.Contains({"AA,AAA"}, [Type]) then 1 else 0)

This works fine until I have a contact records that has the Type of e.g. AA, AAA, BB (the Custom Fields shows 0).

I assumed (wrongly!) that List.Contains would work if the Type field contained both of the choices (i.e. AA and AAA) no matter what else the field contained (i.e. BB).

So, what I want to acheive is:
Put 1 in the new Custom Field if the Type field contains AA and AAA and any other Type (or not),

For clarity, the following scenarions would result in 1 or 0 as shown:

Type = AA, AAA (field equals 1)
Type = A, AA (field equals 0)
Type = AA, AAA, BB (field equal0 1)
Type = BB, BBB (field equals 0)

How would I achieve this? I'm not wedded to using the List.Contains function if there's a better way!

Many thanks
Jon

2 ACCEPTED SOLUTIONS
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @jonclay ,

 

How about this?

tackytechtom_0-1736108061107.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("i45WcnTUUXB0dFSK1QGyQUwICyKqo+DkBOY7OYGYQHYsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([Type], "AA") and Text.Contains([Type], "AAA") then 1 else 0)
in
    #"Added Custom"

 

In a nutshell, I just used a simple if clause...

 

Let me know if this solves your issue 🙂

 

/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

Anonymous
Not applicable

Hi @jonclay ,

 

Pls has your problem been solved? If so, accept the reply as a solution. This will make it easier for the future people to find the answer quickly.

If not, please provide a more detailed description, preferably some virtual sample data, and the expected results.

 

Best Regards,

Stephen Tao

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @jonclay ,

 

Pls has your problem been solved? If so, accept the reply as a solution. This will make it easier for the future people to find the answer quickly.

If not, please provide a more detailed description, preferably some virtual sample data, and the expected results.

 

Best Regards,

Stephen Tao

 

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.ContainsAll(Text.Split([Type],", "),{"AA","AAA"}))
in
    #"Added Custom"

Hope this helps.

Ashish_Mathur_0-1736133921222.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
tackytechtom
Most Valuable Professional
Most Valuable Professional

Hi @jonclay ,

 

How about this?

tackytechtom_0-1736108061107.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("i45WcnTUUXB0dFSK1QGyQUwICyKqo+DkBOY7OYGYQHYsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([Type], "AA") and Text.Contains([Type], "AAA") then 1 else 0)
in
    #"Added Custom"

 

In a nutshell, I just used a simple if clause...

 

Let me know if this solves your issue 🙂

 

/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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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