Power Query to count the occurrence of a "fs -","ss -", "ff -", "sf -"

aaewalsh

Board Regular
Joined
Jan 9, 2023
Messages
97
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I have a column with data like below
A1000 ff, A2000 fs -7, A2010 ss -4

And so on.

What I need is a query that will query the column and return a combined count of the occurrence of "fs -","ss -", "ff -", "sf -".

Any help is much appreciated.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Are there different strings in the same cell separated by a comma as you indicated, or one string per cell in a column, or an entire range with strings?
 
Upvote 0
Yses this is an example of a cell, they are all separated with a comma BD-1020: FF -3, BD-1067: FS -1, BD-1050: FS, BD-1085: SF 5d,
 
Upvote 0
Here's a custom function you could use

Power Query:
(tbl as table, col as text, find as list) =>
let
    CountOfOneText = (t as text, find as text) => (Text.Length(t) - Text.Length(Text.Replace(t,find,"")))/Text.Length(find),
    CountMultiple = (t as text, find as list) => List.Accumulate(find, 0, (s,c)=> s + CountOfOneText(t,c)),
    Result = List.Accumulate(Table.Column(tbl, col), 0, (s,c)=> s + CountMultiple(c, find))
in
    Result

say you call it CountOccurrences, then if you have a table (step) name say Source with column named Data then you would call the custom function by the following syntax

Power Query:
CountOccurrence(Source, "Data", {"ss -", "ff -", "sf -", "fs -"})
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top