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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Krcmajster
Helper IV
Helper IV

CONTAINSSTING with multiple values from different column

I am trying to use column from one table as a slicer, to filter different table. Filter should be check if the value contains any of the selected values.

issue.PNG

I wanted to use count to filter if the count is greater or equal to one. 

I have the following measure that works if single value is selected but I am struguling to find a way to solve it when multiple values are selected:

CALCULATE (
    COUNT ( Data[Countries] ),
    FILTER ( Data, CONTAINSSTRING ( Data[Countries], VALUES( ( Slicer[Country] ) ) )
))



1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Krcmajster ,

 

Agree with @amitchandak .

Please transform the table to:

Eyelyn9_0-1652755347529.png

Here is the whole M syntax

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvR1DfJ0dgzWUXD1dXVUitUBCgU4OmPl6ijAVIMl4CqgcmB1CBWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Countries = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Countries", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Countries", "Countries - Copy"),
    #"Renamed Columns" = Table.RenameColumns(#"Duplicated Column",{{"Countries - Copy", "Country"}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Renamed Columns", {{"Country", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Country"),
    #"Trimmed Text" = Table.TransformColumns(#"Split Column by Delimiter",{{"Country", Text.Trim, type text}})
in
    #"Trimmed Text"

Then createa measures:

If contains = IF(MAX('Data'[Country]) in ALLSELECTED(Slicer[Country]),1,0)
Filter = 
var _t=ADDCOLUMNS('Data',"Flag",[If contains])
return SUMX(FILTER(_t,[Countries]=MAX('Data'[Countries])),[Flag])

Output:

Eyelyn9_1-1652756305970.png

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Krcmajster ,

 

Agree with @amitchandak .

Please transform the table to:

Eyelyn9_0-1652755347529.png

Here is the whole M syntax

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvR1DfJ0dgzWUXD1dXVUitUBCgU4OmPl6ijAVIMl4CqgcmB1CBWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Countries = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Countries", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Countries", "Countries - Copy"),
    #"Renamed Columns" = Table.RenameColumns(#"Duplicated Column",{{"Countries - Copy", "Country"}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Renamed Columns", {{"Country", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Country"),
    #"Trimmed Text" = Table.TransformColumns(#"Split Column by Delimiter",{{"Country", Text.Trim, type text}})
in
    #"Trimmed Text"

Then createa measures:

If contains = IF(MAX('Data'[Country]) in ALLSELECTED(Slicer[Country]),1,0)
Filter = 
var _t=ADDCOLUMNS('Data',"Flag",[If contains])
return SUMX(FILTER(_t,[Countries]=MAX('Data'[Countries])),[Flag])

Output:

Eyelyn9_1-1652756305970.png

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

amitchandak
Super User
Super User

@Krcmajster , I doubt searching multiple values as a table. Better to split the country in the table into multiple rows in power query

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