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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Count how many times a word is in a Column

Hi Experts

 

Hi, I have a column of text separated by a semi colon, e.g.

 

Col1

word1;word2

word1;word3

word3;

word4

word1

etc etc

 

I would like to count how many instances of each word in each row and have a total but comparing it against a table of possible words, result would be:

 

word 1 = 3

word 2 = 1

word 3 = 2

etc

 

the following measure does not work when you have word1;word2

 

Count = SUMX(SearchWords,IF(LEN(SUBSTITUTE(SearchWords[SearchWords],[Words],""))<LEN(SearchWords[SearchWords]),1,0))

HELP

1 ACCEPTED SOLUTION
Barthel
Solution Sage
Solution Sage

Hey @Anonymous 
You can use the CONTAINSSTRING function. I have added a new table with all unique words, which I reference in the DAX measure.

Measure = 
VAR _search_word = 
    SELECTEDVALUE ( search_words[search_word] )
VAR _result =
    CALCULATE ( 
        COUNTROWS ( 'Table' ),
        CONTAINSSTRING ( 'Table'[Col1], _search_word )
    )
RETURN
    _result

Result:

Barthel_0-1672656864902.png

View solution in original post

6 REPLIES 6
Barthel
Solution Sage
Solution Sage

Hey @Anonymous 
You can use the CONTAINSSTRING function. I have added a new table with all unique words, which I reference in the DAX measure.

Measure = 
VAR _search_word = 
    SELECTEDVALUE ( search_words[search_word] )
VAR _result =
    CALCULATE ( 
        COUNTROWS ( 'Table' ),
        CONTAINSSTRING ( 'Table'[Col1], _search_word )
    )
RETURN
    _result

Result:

Barthel_0-1672656864902.png

Hey @Barthel 
Thank you for your resposne.
Just a query 🙂

I guess is the above logic wont work if the same name comes in the row more than once correct?

meaning  word1;word2;word1. How should we handle this with above logic?




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com

@NandanHegde,

I think this is very difficult to realize in DAX, and I honestly don't have a good answer for that right now. On the other hand, I think the easiest way is to edit the table in Power Query, splitting each cell into new rows using the separator. Each word than equals one row/column. This way you can still use the above formula. In fact, you don't have to use CONTAINSSTRING anymore and you can simply use an equals statement.

Anonymous
Not applicable

Thank you sir perfect

NandanHegde
Super User
Super User

Hey, You can probably try the below approach :

1) split the column based on semi colon

2) Then transpose so that each row is equivalent to a word

3) Then create a measure by Summarize

something like:

SUMMARIZE(Table, Table[Column], "WordCount", COUNT(Table[Column]))




----------------------------------------------------------------------------------------------
Nandan Hegde (MSFT Data MVP)
LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66
GitHUB Profile : https://github.com/NandanHegde15
Twitter Profile : @nandan_hegde15
MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942
Topmate : https://topmate.io/nandan_hegde
Blog :https://datasharkx.wordpress.com
Anonymous
Not applicable

HI just tried this also not working too

New Count =
var _a = SELECTEDVALUE('DimExoskeleton'[Process])
var _b = HASONEVALUE('DimExoskeleton'[Process])
var _c = countrows( FILTER('Daily Survey', 'Daily Survey'[InwhatprocessdidyouusetheExoskel (new)] = _a ))
Return
if (_b, if (ISBLANK(_c), 0, _c), BLANK() )

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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