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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
sumant28
New Member

Using CONTAINSSTRING function inside CALCULATETABLE to filter partial string matches to multiple str

table =
DATATABLE (
    "Name", STRING,
    "Code", STRING,
    "ID", INTEGER,
    {
        { "asldkjfaaa", "ABC", 1 },
        { "jdfkbbb", "ABC", 2 },
        { "dskhgaaa", "XYZ", 3 },
        { "hfdjk", "ABC", 4 },
        { "eowyyui", "ABC", 5 }
    }
)

filter =
CALCULATETABLE (
    'table',
    'table'[Code] = "ABC",
    FILTER ( 'table', NOT ( CONTAINSSTRING ( 'table'[Name], "aaa" ) ) )
)

 

I am using powerbi and I am selecting the New table button first to create the data and second to filter the data. What I am tripping over is the fact that CONTAINSSTRING only accepts two arguments and the second argument has to be a string rather than the option of multiple strings. Moreover I cannot repeat the function argument line in the CALCULATETABLE list of filters. The only solution I have now is to wrap the entire code block inside a FILTER argument for each partial string match I want to exclude. I am wondering if there is something better

3 REPLIES 3
tamerj1
Community Champion
Community Champion

Hi @sumant28 

you can do

filter =
CALCULATETABLE (
'table',
'table'[Code] = "ABC",
NOT ( CONTAINSSTRING ( 'table'[Name], "aaa" ) )
)

 

or

 

filter =
FILTER (
'table',
'table'[Code] = "ABC"
&& NOT ( CONTAINSSTRING ( 'table'[Name], "aaa" ) )
)

I forgot to mention in my original post that I don't just want to filter out a partial match to "aaa" but also to "bbb" and so on. My actual problem includes a list of about six such strings. I can have my query take the form of something like 

FILTER(FILTER(FILTER....

But I am not satisfied with how that solution looks

tamerj1
Community Champion
Community Champion

@sumant28 

Definitely you need to iterate ove that list but that is fine, ot is just a small list of 6 rows. For sure there will be room for optimization but you need to be specific about what exactly are you trying to accomplish. 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.