Forum Discussion
jpattamthanam
5 years agoFrequent Visitor
A simple way for COUNTIF function in power query
Hello Community, I have a data set as shown below. Is there a way to have this done in power query editor. Column A and B is the Data input and Column C and D are the results expected. ...
- 5 years ago
Second column with countif added.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlLSUTIGYkMwjtWBiMBEjcEipkCWKVTUCEXEBIzBugwMQCZYWqKYZQFiggmEXoQYVHcsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [C1 = _t, C2 = _t, C1Desired = _t, C2Desired = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"C1", Int64.Type}, {"C2", Int64.Type}, {"C1Desired", Int64.Type}, {"C2Desired", Int64.Type}}), AddedIndex = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type), #"Added Custom" = Table.AddColumn(AddedIndex, "SUMIF_1_argument", each if [Index] = 0 then {AddedIndex{[Index]}[C1], AddedIndex{[Index]}[C2]} else {AddedIndex{[Index]-1}[C1], AddedIndex{[Index]-1}[C2], AddedIndex{[Index]}[C1], AddedIndex{[Index]}[C2]}), #"Added Custom1" = Table.AddColumn(#"Added Custom", "SUMIF_2_argumentC1", each #"Added Custom"{[Index]}[C1]), #"Added Custom2" = Table.AddColumn(#"Added Custom1", "ResultC1", (FirstIterator)=> List.Count( List.Select( FirstIterator[SUMIF_1_argument], each _ = FirstIterator[SUMIF_2_argumentC1]))), //second column #"Added Custom3" = Table.AddColumn(#"Added Custom2", "SUMIF_2_argumentC2", each #"Added Custom"{[Index]}[C2]), #"Added Custom4" = Table.AddColumn(#"Added Custom3", "ResultC2", (FirstIterator)=> List.Count( List.Select( FirstIterator[SUMIF_1_argument], each _ = FirstIterator[SUMIF_2_argumentC2]))) in #"Added Custom4"
CNENFRNL
5 years agoCommunity Champion
Hi, jpattamthanam , in general, you may transform the target region (eg A1:B2 in your example) to list and use
List.Count(List.PositionOf( list , "substring" , Occurrence.All))
to count the occurrence of a specific string.