Count the number of times an item occurs in a list

This is a relatively straightforward task in other programming languages, but I’m having a little trouble here! Here is a column, and I want to count the number of times each unique item occurs. So in the first row, for instance, I would get the count for 21 as 3, the count for 55 as 2, and the count for the rest as 1

My main reason for doing this is because I want to write an if statement that says, in plain English, “If the item occurs more than twice do something, add it to this column, else don’t.”

Hi @Nick_Place
and welcome to Coda Community! :handshake:

Have a look at this example and let me know if it does work for you:

From what I understood, you need to define a threshold and trigger an action only for items that reach or overtake that threshold.

Here’s an explanation of the formula:

thisRow.[Unsed PTs].Unique().FormulaMap(CurrentValue         // take the unique elements of the list
      .WithName(instance,                                 // give each iterating element the name 'instance'
        thisRow.[Unsed PTs].CountIf(CurrentValue = instance)     // count the number of that instance in the list
          .WithName(occurrences,                        // and give it the name 'occurrences'
            if(occurrences >= slider_Threshold, instance, "")   // if occurrences are equal or greater than the threshold, 'print' the instance, otherwise blank, 
  ).Filter(CurrentValue.IsNotBlank()                                    // for beautification purposes only: removing all blanks

I hope this helps!


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.