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
Gokul
Helper IV
Helper IV

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
v-shex-msft
Community Support
Community Support

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
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

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
If this post helps, please consider accept as solution to help other members find it more quickly.

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.