cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Crisse Frequent Visitor
Frequent Visitor

Counting how many times certain word is in column per row

hi

 

I have tried to understand how to calculate next

 

I have roughly 5000 rows in table1

I have column "Info requests" in my table and it includes data like

 

caseID                           info requests

11111                            

11112                            responded;

11113                            responded; waiting response

11114                            responded; responded; cancelled

11115                            cancelled; responded;

 

Now I want to create new column which includes information how many times responded has been visible for each caseID

my expectation is to have next kind of info

 

caseID                           info requests                                             IR responded

11111                                                                                          

11112                            responded;                                               1

11113                            responded; waiting response;                  1

11114                            responded; responded; cancelled;            2

11115                            cancelled; responded;                              1

 

I do not know how to do it, can you help?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support Team
Community Support Team

Re: Counting how many times certain word is in column per row

@Crisse ,

 

You may also add a custom column.

List.Count(Text.Split([info requests], "responded")) - 1
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.
4 REPLIES 4
Super User
Super User

Re: Counting how many times certain word is in column per row

@Crisse  Please try using "Split Column" and "Group By" options to achieve this in Power Query Editor.

 

Here is the M-code generated by using those two steps on the sample data.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgQBJR0lpVgdCMcIyClKLS7Iz0tJTbGGCxujCJcnZpZk5qUrQESKUxHqTFDUIVjJiXnJqTk5yEaaApUihJHtjAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [CaseID = _t, InfoRequests = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CaseID", Int64.Type}, {"InfoRequests", type text}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"InfoRequests", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "InfoRequests"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"InfoRequests", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type1", {"CaseID", "InfoRequests"}, {{"CountResponded", each Table.RowCount(_), type number}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each ([InfoRequests] = "responded"))
in
    #"Filtered Rows"

image.png



Did I answer your question? Mark my post as a solution !

Proud to be a Datanaut !





Super User
Super User

Re: Counting how many times certain word is in column per row

@Crisse 

 

As a calculated column in DAX you can use

 

Column =
PATHLENGTH ( SUBSTITUTE ( [info requests], "responded", "|" ) ) - 1

pathtocount.png

Crisse Frequent Visitor
Frequent Visitor

Re: Counting how many times certain word is in column per row

Thank You, I manage to get at least some data Smiley Wink

Highlighted
Community Support Team
Community Support Team

Re: Counting how many times certain word is in column per row

@Crisse ,

 

You may also add a custom column.

List.Count(Text.Split([info requests], "responded")) - 1
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.