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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
DavidC2020
Frequent Visitor

Calculating a measure based on finding text in a column

Hi,

 

I'm looking for some advice on how I can create a measure that counts the number of customers that do not have a specific event recorded against them.  An example of this is:

 

  • I have a Customers table
  • I have a Sales Fact table joined to the Customers (I do a DISTINCT on Customer Key to calculate the number of customers)
  • I have a Customer Note table connected to the Customer table

I would like to create a calculation which searches for specific text in the Customer Notes table and then filters the Customer Count measure to include Customers that don't have the search string in a Customer Note.

 

I've tried doing it the other way round first, calcualting the customer count that does have a specific text in a note, but I'm not having much luck:

 

Missing Fee Note =
CALCULATE(
[Customer Count],
FILTER ( Customer, CONTAINSSTRING ( 'Customer Note'[Note Text], "search text" ) )

 

I get an error above which says that it can't determine a single value.  Any help or pointers would be appreicated.

 

Thanks

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@DavidC2020 , make sure Customer Count is a measure

Try like example

 

CALCULATE(
count(Sales[Customer ID]) ,
FILTER ( Customer, not CONTAINSSTRING ( 'Customer Note'[Note Text], "search text" ) ) //added not , remove as per need

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

3 REPLIES 3
v-yinliw-msft
Community Support
Community Support

Hi @DavidC2020 ,

 

You can try the following methods.

 

Here's my test table:

 

Customer Note Table:

vyinliwmsft_0-1663133120996.png

 

 

Customer Table:

vyinliwmsft_1-1663133121001.png

 

 

Sales Fact Table:

vyinliwmsft_2-1663133121003.png

 

 

Measure:

 

Missing Fee Note =

CALCULATE (

    [Customer Count],

    FILTER (

        ALL ( 'Customer Note' ),

        CONTAINSSTRING ( 'Customer Note'[Note Text], "fail" )

    )

)

vyinliwmsft_3-1663133121006.png

 

 

In your code, the first argument to the filter function should probably be used Customer Note.

 

Missing Fee Note =
CALCULATE(
[Customer Count],
FILTER ( Customer, CONTAINSSTRING ( 'Customer Note'[Note Text], "search text" ) )

 

Is this the result you expect?

 

Best Regards,

Community Support Team _Yinliw

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

Thank you for the example.  I was looking for instances where the text was not contained within the string.

amitchandak
Super User
Super User

@DavidC2020 , make sure Customer Count is a measure

Try like example

 

CALCULATE(
count(Sales[Customer ID]) ,
FILTER ( Customer, not CONTAINSSTRING ( 'Customer Note'[Note Text], "search text" ) ) //added not , remove as per need

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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