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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
JedShields
New Member

CONTAINSTRING not working in FILTER statement?

Hello all,


I've got a measure that counts all sites in a table (keyMSSummary) after filtering sites that have a specific Activity Name, and also filter the column Focus Area for anything that contains "eMVP".  The code below doesn't work and I think it's the CONTAINSTRING part.

    COUNTX(
        FILTER(
            'keyMSSummary',
            'keyMSSummary'[activity_name] = "4G X Symmetry New POP 4G/5G – Cellnex 127 TowerCo"
            && CONTAINSSTRING('keyMSSummary'[focus_area], "eMVP")),
            'keyMSSummary'[ms5_SiteAccessed_ACT]
        )

Any suggestions?
2 ACCEPTED SOLUTIONS
v-yilong-msft
Community Support
Community Support

Hi @JedShields ,

I create a table as you mentioned.

vyilongmsft_0-1737614131481.png

Then I think you can change your DAX code:

Measure = 
    COUNTX(
        FILTER(
            'keyMSSummary',
            'keyMSSummary'[activity_name] = "4G X Symmetry New POP 4G/5G – Cellnex 127 TowerCo"
            && SEARCH("eMVP", 'keyMSSummary'[focus_area], 1, 0) > 0
        ),
        'keyMSSummary'[ms5_SiteAccessed_ACT]
    )

vyilongmsft_1-1737616213483.png

 

Best Regards

Yilong Zhou

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

rohit1991
Super User
Super User

Use FIND instead of CONTAINSSTRING for reliability:

 

CountSites :=
COUNTX(
FILTER(
'keyMSSummary',
'keyMSSummary'[activity_name] = "4G X Symmetry New POP 4G/5G – Cellnex 127 TowerCo"
&& FIND("eMVP", 'keyMSSummary'[focus_area], 1, 0) > 0
),
'keyMSSummary'[ms5_SiteAccessed_ACT]
)

 

If focus_area might be blank, handle it with COALESCE:

FIND("eMVP", COALESCE('keyMSSummary'[focus_area], ""), 1, 0) > 0

 

This ensures proper evaluation of the substring check.

View solution in original post

6 REPLIES 6
rohit1991
Super User
Super User

Use FIND instead of CONTAINSSTRING for reliability:

 

CountSites :=
COUNTX(
FILTER(
'keyMSSummary',
'keyMSSummary'[activity_name] = "4G X Symmetry New POP 4G/5G – Cellnex 127 TowerCo"
&& FIND("eMVP", 'keyMSSummary'[focus_area], 1, 0) > 0
),
'keyMSSummary'[ms5_SiteAccessed_ACT]
)

 

If focus_area might be blank, handle it with COALESCE:

FIND("eMVP", COALESCE('keyMSSummary'[focus_area], ""), 1, 0) > 0

 

This ensures proper evaluation of the substring check.

Thanks for the advice, I'll make the changes.

JedShields
New Member

Thanks all.

Apologies for the delay, your solutions all worked, but so did my original CONTAINSSTRING!  It turns out that the text I copied from an excel data source a had a long hyphon in the text, the csv that the PBI report links to has a short hyphon!  Typical XD

v-yilong-msft
Community Support
Community Support

Hi @JedShields ,

I create a table as you mentioned.

vyilongmsft_0-1737614131481.png

Then I think you can change your DAX code:

Measure = 
    COUNTX(
        FILTER(
            'keyMSSummary',
            'keyMSSummary'[activity_name] = "4G X Symmetry New POP 4G/5G – Cellnex 127 TowerCo"
            && SEARCH("eMVP", 'keyMSSummary'[focus_area], 1, 0) > 0
        ),
        'keyMSSummary'[ms5_SiteAccessed_ACT]
    )

vyilongmsft_1-1737616213483.png

 

Best Regards

Yilong Zhou

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

vivek31
Resolver II
Resolver II

HI @JedShields ,

you can use FIND function to place of CONTAINSSTRING 
FIND("eMVP", 'keyMSSummary'[focus_area], 1, 0) 

BeaBF
Super User
Super User

@JedShields Hi! Try to test the two conditions indipendently:

 

1.

COUNTROWS(
FILTER(
'keyMSSummary',
'keyMSSummary'[activity_name] = "4G X Symmetry New POP 4G/5G – Cellnex 127 TowerCo")
)
)

 

2.

COUNTROWS(
FILTER(
'keyMSSummary',
CONTAINSSTRING('keyMSSummary'[focus_area], "eMVP")
)
)

 

 

which is not working?

 

BBF

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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