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

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

Reply
chipchidster
Resolver I
Resolver I

Unable to use parameters in a list.contains

I am sure I am being stupid, but I cannot work out how to get this to work and so I am hoping someone knows what I am doing wrong.

I have a large if/else statement written using powerquery/m code that assigns a tribe name based on a project key (see below).

if List.Contains({"POS","PRS","PDS"},[project_key]) then "PIM Mission"
else
if List.Contains({"CUS","SCV","LS","CL"},[project_key]) then "Attract, Onboard, Service & Retain"
else
"no tribe"

I would like to replace these lists with parameters so that the tribe allocations are easier to modify if needed.  However if I try and use a parameter instead, it doesn't work.

if List.Contains({paramPIMSquads},[project_key]) then "PIM Mission"
else
if List.Contains({paramAOSRSquads},[project_key]) then "Attract, Onboard, Service & Retain"
else
"no tribe"

Perhaps niaively I was expecting pbi to drop the param in a text string but it doesn't appear to do that.  Am i being stupid or is this one of those really odd pbi deficiencies?

 

1 ACCEPTED SOLUTION
chipchidster
Resolver I
Resolver I

Thank you to both contributors who offered up solutions - I did finally manage to get this working, and it was far simpler that I thought.  I was using List.Contains when I should have been using Text.Contains.  Thank you to @Anonymous for pointing that out in his reply.  Just swapped that and everything works like a charm.

View solution in original post

4 REPLIES 4
chipchidster
Resolver I
Resolver I

Thank you to both contributors who offered up solutions - I did finally manage to get this working, and it was far simpler that I thought.  I was using List.Contains when I should have been using Text.Contains.  Thank you to @Anonymous for pointing that out in his reply.  Just swapped that and everything works like a charm.

Anonymous
Not applicable

Hi, @chipchidster 
Based on your information, I create sample table:

vyohuamsft_0-1728539834034.png

Create parameters:

vyohuamsft_1-1728539880784.png

 

Then create new custom column, replace List.Contains with Text.Contains, here is M expression:

 

if Text.Contains(paramPIMSquads, [project_key]) then "PIM Mission"
else if Text.Contains(paramAOSRSquads, [project_key]) then "Attract, Onboard, Service & Retain"
else "no tribe"

 

vyohuamsft_2-1728540001848.png


Here is my preview:

vyohuamsft_3-1728540211641.png

 

Or you can create query, like this:

vyohuamsft_0-1728543341876.png

 

Use the following expression:

if List.Contains(Query1, [project_key]) then "PIM Mission"
else if List.Contains(Query2, [project_key]) then "Attract, Onboard, Service & Retain"
else "no tribe"

vyohuamsft_1-1728543393753.png

 

 

How to Get Your Question Answered Quickly

Best Regards

Yongkang Hua

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

rajendraongole1
Super User
Super User

Hi @chipchidster - You're on the right track! The issue stems from how Power Query handles parameters and lists. When you replace the hardcoded list of values with a parameter, Power Query treats it differently.

 

can you check function

if List.Contains({paramPIMSquads}, [project_key]) then "PIM Mission"

 

Instead of wrapping the parameter in curly braces, use the parameter directly as it's already a list

if List.Contains(paramPIMSquads, [project_key]) then "PIM Mission"
else if List.Contains(paramAOSRSquads, [project_key]) then "Attract, Onboard, Service & Retain"
else "no tribe"

 

This will allow you to easily modify the lists later by adjusting the parameters instead of rewriting the entire if statement. try this and i hope it works.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





No, that doesn't work.  If I use the parameter like that it throws the following error:

Expression.Error: We cannot convert the value ""CUS","CL","SCV","LS..." to type List

 

I have tried using Text.toList(paramAOSRSquads) but that doesn't work either, and I get the following error:

Expression.Error: We cannot apply an index of type Text.
Details:
Value=[Function]
Index="CUS","CL","SCV","LS"

 I have also tried with the list entries in quotes (as above) and without, and also with the list enclosed in curly braces - again, no dice.

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 Solution Authors