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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Mixing CONTAINSSTRING & IN keywords (dynamic number of values)

Hey everyone,

 

I've been trying to come up with a way to make CONTAINSSTRING & IN work together.


Here is some context :

I have an SSRS text field where the user can enter multiple values with a ',' as delimiter.

The text or number of values typed in is totally up to the user and I can't use a dropdown list as there is too much value to display.

 

I would like to use that input as FILTER for my DAX query, something like that :

FILTER(
VALUES('Country'[_Country]),
CONTAINSSTRING('Country'[_Country], IN {"Fi", "Ja")
)

 

I would then get every result with Country being either Fiji, Finland, Jamaica or Japan.

 

The problem that I face is obviously that CONTAINSSTRING expects 2 arguments, and I'm pretty new to DAX hence I don't know how to "format" the second argument to handle multiple values.

I've seen a lot of answers using multiple CONTAINSSTRING statements with || operators but this cannot work since the input I get is dynamic.

 

Any idea ?

 

Thank you for your help 

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

Measure = FILTER(
VALUES('Country'[Country]),
CONTAINSSTRING('Country'[Country], "Fi*Ja*Ch")
)

vzhangti_0-1662016281070.png

You retrieve one, two, or three values, and you can concatenate strings with "*". 

  • You can use ? and * wildcard characters. Use ~ to escape wildcard characters.

CONTAINSSTRING function (DAX) - DAX | Microsoft Docs

 

Best Regards,

Community Support Team _Charlotte

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

Anonymous
Not applicable

Hey,

 

Thank you for your help & sorry for the delayed answer.

 

I tried your solution but I don't think this is working. Because it seems to be searching for a word that starts with 'Fi', has 'Ja' in the middle of it & end with 'Ch' I think ?

What I would need is something that consider evey single string independently.

 

 

An equivalent in SQL would be :

  WHERE Country LIKE '%Fi%' OR Country LIKE '%Ja%'


I'm wondering if it's even possible at this point.

Anonymous
Not applicable

Sorry, maybe I didn't explained it clearly enough. 

So this solution would work but those strings were just examples.

 

In a real situation, the user will type the string values in a SSRS textbox which means I can't use this solution as I may retrieve one, two or maybe three values.

Tutu_M_0-1661345164319.png

I can't work with hardcoded value basically 😔

amitchandak
Super User
Super User

@Anonymous , Try like

 

FIlter('Country', CONTAINSSTRING('Country'[_Country],"Fi") || CONTAINSSTRING('Country'[_Country],"Ja") )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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