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
KCfromDC
Frequent Visitor

Counting the number of occurrences of a string in different columns

Hi all-

I've gone around in circles trying to get this to work and am at my wit's end. I'm sure it's an easy solution, but I'm still learning PoweBI and none of my searches have come up with an answer.

 

I have a table coming from a system where the user can add up to three tags to a record. Unfortunately, all of the tags get combined into one column, and they're not in alphabetical order. Fortunately, they are delimited by a comma, so I was able to split them across three columns:

 

A.1A.2A.3
AppleBananaCarrot
AppleCarrot 
BananaAppleCarrot
Carrot  
BananaCarrotApple
CarrotBanana 

 

I've been trying to count the total number of occurences of each tag in the table as a measure. (E.g., total # of "Apple" = 4, Bananas = 4, Carrot = 5).

 

Unfortunately, using a filter causes the other two columns to not be counted - for example, column A.1 filtered to "Apple" will not count the occurrences in rows #3 and #5 (columns A.2 and A.3, respectively) as it can't "see" them.

 

I've tried using the following to clear the filter, but it still only counts what's in the first column.

 

 

 

 

AppleCount = CALCULATE(
COUNROWS(FILTER(Table,[A.1]="Apples"))) +
CALCULATE(
COUNTROWS(FILTER(ALL(Table),Table[A.2]="Apples")))

 

 

 

 

 

Any help is much appreciated. Thank you!

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@KCfromDC  I answered a similar question Here 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi @KCfromDC,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
smpa01
Super User
Super User

@KCfromDC  I answered a similar question Here 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
KCfromDC
Frequent Visitor

Hi all-

Thank you - not sure if this will work, though, as it's a 3,000+ row dataset with 10 columns. I wanted to use the above as a simpler example, so unpivoting them may not work... 😕

NidhiBhusari
Helper IV
Helper IV

Hi @KCfromDC ,

Go to power Query and unpivot the columns then add conditional column to assign ID to the tags. AFter following these steps you will get below table.

NidhiBhusari_0-1638257684789.png


Then drag ID's column(Take count of it) in Table visual.

NidhiBhusari_1-1638257813675.png

 

amitchandak
Super User
Super User

@KCfromDC , When you split them , you can split rows, in this case that would be a better option

Split Column Power Query: https://youtu.be/FyO9Vmhcfag

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.