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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
bb72
Regular Visitor

Counting how many times a word is in a column

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

 

I see an example here:

https://community.powerbi.com/t5/Desktop/Counting-how-many-times-a-word-is-in-a-column/m-p/206657#M9...

 

# Depression = CALCULATE(COUNTAX('TableName','TableName'[Emotional Depression]),'TableName'[Emotional Depression]="Depression")

 

But it is using a hard coded word to search for instead of a list in another table/column.

 

As I have 30 words to search for, would rather reference something else to supply statically in the search criteria.

 

Any suggestions pls?

 

thanks!

BB

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Given the following Enter Data queries:

 

SearchWords

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKs8vSjG0BpFGSrE6yHxjON/YGs40QShSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [SearchWords = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SearchWords", type text}})
in
    #"Changed Type"

Words

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKs8vSjFUitWBsIzgLGM4y0QpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Words = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Words", type text}})
in
    #"Changed Type"

 

Create this colum in your Words table:

 

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


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@bb72,

 

You may first select Split Column By Delimiter in Query Editor.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Given the following Enter Data queries:

 

SearchWords

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKs8vSjG0BpFGSrE6yHxjON/YGs40QShSio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [SearchWords = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"SearchWords", type text}})
in
    #"Changed Type"

Words

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKs8vSjFUitWBsIzgLGM4y0QpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Words = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Words", type text}})
in
    #"Changed Type"

 

Create this colum in your Words table:

 

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


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thank you, this is almost perfect. However my column of words I am searching for, is of format:

 

word1;word2

 

Which your suggestion doesn't match on unfortunately.

 

COUNTIF works nicely in Excel, is there an equivalent ?

 

Thank u so much!

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.