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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
julienvdc
Helper III
Helper III

Count appearance of string in a comma-separated data column

Hey there,

 

I have a table with a list of strings as so:

String A
String B
String C
String D
String E
String F

 

Then I have another table with a column that lists a series of comma-sperated strings:

 

String A, String D, String E
String B, String D, String E
String A, String B
String A

 

I would like to be able to build a measure that would count the amount of appearance for each string 🙂

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@julienvdc you can add a Column using this

 

Count of Rows = 
VAR __dataToFind = Data[Column1]
RETURN
CALCULATE ( COUNTROWS ( List ), CONTAINSSTRING ( List[Column1],  __dataToFind ) )

 

 

and here is the output:

 

parry2k_0-1631889564228.png

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 

following expression. Change table and column name as per your model:

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@julienvdc you can add a Column using this

 

Count of Rows = 
VAR __dataToFind = Data[Column1]
RETURN
CALCULATE ( COUNTROWS ( List ), CONTAINSSTRING ( List[Column1],  __dataToFind ) )

 

 

and here is the output:

 

parry2k_0-1631889564228.png

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 

following expression. Change table and column name as per your model:

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Greg_Deckler
Community Champion
Community Champion

@julienvdc You can use Count of List items:

Count of List Items - Microsoft Power BI Community

In your case: 

Measure =
  VAR __String = MAX('Table'[String])
  VAR __Strings = CONCATENATEX('OtherTable',[String],", ")
  VAR __Length = LEN(__String)
RETURN
  ( LEN(__Strings) - LEN(SUBSTITUTE(__Strings,__String,"")) ) / __Length


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hey! 

Thanks 🙂

I gave it a try, but it doesn't appear to be successful... but in all honesty I've blindly followed your formula, replacing elements where needed. But I don't really understand the formula... Would you mind explaining what you're doing with that formula please 🙂 ?

@julienvdc Sure:

Measure =
  VAR __String = MAX('Table'[String])
// This gets the current string to search for so imagine a table visual with the column from your first table you posted in the table visual.

  VAR __Strings = CONCATENATEX('OtherTable',[String],", ")
// This is grabbing all of the strings from the second table you posted and concatenating them into a single string

  VAR __Length = LEN(__String)
// Get the total length of the string you are searching for

RETURN
  ( LEN(__Strings) - LEN(SUBSTITUTE(__Strings,__String,"")) ) / __Length
// Get the total length of the concatenated strings and then get the length of the concatenated list of strings where you substitute the search string with nothing. You take the difference of those lengths and divide by the length of the string to find out how many times the string was replaced essentially or effectively the number of times the search string occurred in the concatenated list of strings.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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