I have some data in google sheet which I want to filter based on a certain criteria and return a corresponding value from another column. Lastly, count the number of elements in the returned column. Here is a sample data:
| A | B | |
|---|---|---|
| 1 | Initials | Application Reference | 
| 2 | MWB.KBB | 1001 | 
| 3 | JET,JJB | 1002 | 
| 4 | KBB | 100,310,041,005 | 
| 5 | MKGC | 1006 | 
| 6 | KBB | 1007 | 
Let's say I want to filter the data by searching for "KBB". I want to get all cells that contain the word "KBB" which should be three (3) cells. However, I am only getting two in return. The 1st row that contain two elements in a single cell is not included but it should be included. Lastly, count the elements in the returned column based on the criteria.
Here's the code I have tried:
function filter(){
  //opened ss via url
  const ws = ss.getSheetByName("Sample");
  const range = ws.getRange(2,1,ws.getLastRow() - 1,2).getValues();
  const initial = range.map(function(n){return n[0];});
  const filtered = initial.filter(filterLogic);
  Logger.log(initial); // [MWP, KBB, JET, JJB, KBB, MKGC, KBB]
  Logger.log(filtered); // [KBB, KBB]
}
function filterLogic(name){
  if(name == "KBB"){
    return true;
  } else {
    return false;
  }
}
The above code is only for the criteria. Not included is the counting of elements for the returned value from another column after the filter is applied.
What should I do so I can include the first row that contains the text "KBB" as well in my filtered data. Is there any other way around this?
 
     
    