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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Check if results contain specific string

I think this might be a basic question but I want to create a measure that will let me know if my results contain a specifc string. My data is set up like the below:

Table 1: Orders
order_id

Table 2: Products
order_id
product_type

Orders Products
order_id1 - *product_type


I created a table visual that lists all my orders. In another column I wanted to add a measure that could tell me TRUE, FALSE if my order ID contains a specific product which I would specifiy with a string - "Baseball". There are only about 10 different product types overall. 

I tried: 
Measure  = containsstring((concatenatex(Products,Products[product_type],",")),"Baseball")

It is just way to slow however and I end up exhausing the resources. 

Thanks in advance for any suggestions on how to solve this one!

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your needs, I did the following tests:

M = 
IF ( CONTAINSSTRING ( MAX ( 'Table'[Products] ), "Baseball" ), "True", "False" )

 

v-henryk-mstf_0-1618903802597.png

 


If the problem is still not resolved, please provide a detailed data model (delete sensitive information) or expected results. I will answer for you as soon as possible. Looking forward to your reply.



Best Regards,
Henry

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

5 REPLIES 5
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your needs, I did the following tests:

M = 
IF ( CONTAINSSTRING ( MAX ( 'Table'[Products] ), "Baseball" ), "True", "False" )

 

v-henryk-mstf_0-1618903802597.png

 


If the problem is still not resolved, please provide a detailed data model (delete sensitive information) or expected results. I will answer for you as soon as possible. Looking forward to your reply.



Best Regards,
Henry

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

Ashish_Mathur
Super User
Super User

Hi,

Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AlexisOlson
Super User
Super User

This is an inefficient way to do things because you are concatenating the product type in every single row of Products.

 

A more efficient way is to look at only the different product types in the current filter context and check if any one of those few values contains the string. If none of them do, you get an empty table in the measure below:

 

Measure =
NOT (
    ISEMPTY (
        FILTER (
            VALUES ( Products[product_type] ),
            CONTAINSSTRING ( Products[product_type], "Baseball" )
        )
    )
)
Anonymous
Not applicable

Thanks so much Alexis! I this isn't something I thought of and I think this solution would work - however I am still running into resource issues with this. Perhaps there is just too much data to achieve what I want with a measure alone. 

If you can create a calculated column in your model, that would be more efficient than having to use a measure.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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