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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
gingerclaire
Helper III
Helper III

Count instance of string in column

I have a table (L&L) as below which is connected to my date table:

 

Date           Job role codes concatenated

01/11/22      123b4, 34b56, 2b343, 3a421

03/11/22       123b4, 34b56, 2b343, 3a421

3/10/22         123b4, 34b56, 2b343, 3a421

 

I have another table containing the codes and definitions:

123b4 Vet

34b56  nurse

3a421 manager

 

 

I want to end up with a pie chart or table showing:

 

Job role

Vet        3

Nurse      2

Manager       4

 

How do I relate these two tables and make this happen please?

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@gingerclaire You can either use Power Query Editor to split that column on commas and the unpivot or you could do this:

Measure = 
  VAR __Code = MAX('Table2'[Code])
  VAR __Table = FILTER('Table1',CONTAINSSTRING([Job role codes concatenated],__Code))
  VAR __Result = COUNTROWS(__Table)
RETURN
  __Result


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...

Thank you! I used this and it is working in a table BUT it is using COUNTROWS so is giving me the wrong totals - but i think i worked out why!

One a single row there might be several instances of the same string i.e. each row is an event and there might be 5 or six vets at that event. So it needs to count how often the string/code appears.

Is there a way to do this please?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.