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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
PHEstaciMa1
Helper I
Helper I

Counting occurrence of a particular text in a row

Hi Everyone, I wanted to count occurrence of a particular text in a row filled with multiple entry data e.g. risk prediction, SOP, caution, compliance in a column. Is there a way how to do it? Power BI Query.jpg

 

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @PHEstaciMa1 

Is the result similar to what you want?

vxiaotang_1-1636526458406.png

If yes, you can try this,

1. create a value list table,

vxiaotang_0-1636526054966.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY4xCoAwDEWvEjp7CcFVEB0cikOwoQQ1labg9dW6iKjr433et9b0IU7rjCNBRcpezFBY07JO0ERyPCYOFztFFg9dQnEYnWZabhhJSBVqFPS0kKQC8r5UPfgF3sePzJf207h/HHY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Work systems" = _t]),
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "Work systems", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), {"Work systems.1", "Work systems.2", "Work systems.3"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Work systems.1", type text}, {"Work systems.2", type text}, {"Work systems.3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns")
in
    #"Removed Duplicates"

2. count each value 

count = CALCULATE(COUNTROWS('Table'),FILTER('Table',CONTAINSSTRING('Table'[Work systems],MAX(test[Value]))))

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-xiaotang
Community Support
Community Support

Hi @PHEstaciMa1 

Is the result similar to what you want?

vxiaotang_1-1636526458406.png

If yes, you can try this,

1. create a value list table,

vxiaotang_0-1636526054966.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY4xCoAwDEWvEjp7CcFVEB0cikOwoQQ1labg9dW6iKjr433et9b0IU7rjCNBRcpezFBY07JO0ERyPCYOFztFFg9dQnEYnWZabhhJSBVqFPS0kKQC8r5UPfgF3sePzJf207h/HHY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Work systems" = _t]),
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "Work systems", Splitter.SplitTextByDelimiter(", ", QuoteStyle.Csv), {"Work systems.1", "Work systems.2", "Work systems.3"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Work systems.1", type text}, {"Work systems.2", type text}, {"Work systems.3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns")
in
    #"Removed Duplicates"

2. count each value 

count = CALCULATE(COUNTROWS('Table'),FILTER('Table',CONTAINSSTRING('Table'[Work systems],MAX(test[Value]))))

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Hi Team_Tang, I manage to replicate what you have advise, small glitch is that, whenever I split the column and unpivot it again, there are some data that it is being repeated (even though, I remove the duplicates already). The initial problem I see is that "spaces" between the words make it unique. How can I cleanse this? 

 

PBI query.JPG

 

Hi @PHEstaciMa1 

Thanks for your reply!

 

You can right click on the column, and select Remove Duplicates

vxiaotang_0-1636698923521.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Hi Team_Tang, I figured it out, I used "trim" to remove the spaces before the text and "remove duplicates" its now well working... Again, thank you for the advise! I'll accept it as a solution.PBI query 2.JPG

amitchandak
Super User
Super User

@PHEstaciMa1 , You have search each

 

Countrows(filter(Table,CONTAINSSTRING([Columns],"risk prediction") || CONTAINSSTRING([Columns],"SOP") ))

 

Add others with and (&&)  / or(||)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak just to further clarify, will this become a measure? OR do it will generate a separate column? thanks!

@PHEstaciMa1 , New measure. You can add more filters, if need. But if you want multi select in slicer , that would be little difficult

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.