cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Gokul Member
Member

Counting how many times a word is in a column

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

 

Column :

good,bad

good,worst

worst,

 

etc etc

 

i want the  result would be like this:

 

good = 2

bad = 1

worst = 2

 

i have referred this link (https://community.powerbi.com/t5/Desktop/Counting-how-many-times-a-word-is-in-a-column/m-p/304977#M1... i am not able to understand properly..as am new to power bi ...

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Counting how many times a word is in a column

Hi @Gokul,

 

You can enter to query editor to split your words and use group function to calculate count of each word.

 

Full query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs/PT9FJSkxRitWBcsrzi4pLwFwwS0cpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Detail", each Text.Split([Column],",")),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Detail"),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each [Detail] <> null and [Detail] <> ""),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Detail"}, {{"Count", each Table.RowCount(_), type number}})
in
    #"Grouped Rows"

 

21.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.



For learning resources/Release notes, please visit: | |
1 REPLY 1
Community Support Team
Community Support Team

Re: Counting how many times a word is in a column

Hi @Gokul,

 

You can enter to query editor to split your words and use group function to calculate count of each word.

 

Full query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs/PT9FJSkxRitWBcsrzi4pLwFwwS0cpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Detail", each Text.Split([Column],",")),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Detail"),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each [Detail] <> null and [Detail] <> ""),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Detail"}, {{"Count", each Table.RowCount(_), type number}})
in
    #"Grouped Rows"

 

21.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.



For learning resources/Release notes, please visit: | |