HomeGoogle DocsSpreadsheetRunning Count of Multiple Values in a List in Google Sheets

Running Count of Multiple Values in a List in Google Sheets

Published on

To populate a column with the running count of multiple values present in another column, there is no quick solution. But I do have one array formula which is a combination of MATCH and SORT functions.

Of course, there are other functions involved. But the most prominent ones are the above two functions.

To get the running count of occurrence of a single value in a list, you can use a relatively simple COUNTIF based formula.

Simple Running Count Formula in Google Sheets:

=IF(A2="Apple",COUNTIF($A$2:A2,"Apple"),"")

This formula is in cell B2, then dragged down.

count of occurrences of a value in a list

This formula only returns the running count of a single value. There is one more drawback. This is not an array formula. So you must copy paste the formula downwards.

But what I am providing you is a powerful array formula that I have used in column C in the above example.

The Formula to Populate the Running Count of Multiple Values in a List in Google Sheets

I have entered the following formula in cell C2 in the above example.

=Array_Constrain(iferror(sort({row(A2:A)-row(A2)+2-match(sort(A2:A),sort(A2:A),0),SORT(ROW(A2:A)+2-row(A2)+2,A2:A,1)},2,1),),9^9,1)

Note: Learn Google Sheets Functions.

This formula returns the running count of all the items in the list. This is self-expanding so enter this formula only in the cell C2 (as per the example above) and prior to that keep the cells below it blank.

This Google Sheets running count formula supports infinite ranges. Now here is a new example.

In this, the formula is in cell B2. There are no changes in the formula.

running count of occurrences in Google Sheets

I will explain how to modify the above formula to accommodate any column other than Column A.

How to Use this Array Formula to Populate Running Count of Occurrences of Values

I know your list to find the running count may be in a different column. So I should explain to you how to tweak this formula.

array based multiple occurrences counter formula

In the first formula, the list is in the range A2: A. So you can see the reference A2: A everywhere in that formula.

Here the range is B4: B. So just replace A2: A with B4: B. That is the only changes that you should make.

That’s all about the running count of multiple values in Google Sheets. Enjoy!

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Dynamic Sum Column in SUMIF in Google Sheets

To obtain a dynamic sum column (sum_range argument) in SUMIF, we can utilize the...

Create a Calendar in Excel with a One-Line Dynamic Array Formula

This tutorial explains how to create a calendar in Excel using a one-line formula...

Excel: Month Name to Number & Number to Name

This tutorial showcases the most efficient formulas for converting a month name to a...

Get the First or Last Row/Column in a New Google Sheets Table

If you've recently started using the new Google Sheets TABLE functionality, you may find...

More like this

Dynamic Sum Column in SUMIF in Google Sheets

To obtain a dynamic sum column (sum_range argument) in SUMIF, we can utilize the...

Get the First or Last Row/Column in a New Google Sheets Table

If you've recently started using the new Google Sheets TABLE functionality, you may find...

UNIQUE Function in Visible Rows in Google Sheets

The UNIQUE function doesn't inherently include only visible rows when it returns values, discarding...

8 COMMENTS

  1. Hi, there,

    I have a question, and I think I cannot find the answer here.

    How do I create the group number based on the “Code” given? Notice there are repeating sets.

    WO|CODE|GROUP
    961400279176|2|1
    961400279176|3|1
    961400279176|5|1
    961400279187|2|2
    961400279187|3|2
    961400279187|5|2

    • Hi, Desmond Lee,

      I guess you want to get the group number in column C.

      In cell C2, try this formula.

      =ArrayFormula(FLATTEN(split(rept(sequence(count(B2:B)/3)&"|",3),"|")))

      If that doesn’t help, leave the URL of your sample sheet below (in reply).

  2. How would you implement this same formula, but based on another set of criteria? For example, I want to have a running count of the times “Apple” occurred when column X equals May 2021, and so on?

  3. Hello, Prashanth,

    I’ve been looking for a solution to this problem all over the place and I couldn’t find until I came across your post.

    It’s exactly what I’m looking for but for some reason I can’t get the formula to work.

    I even tried to copy the example exactly as it shows, with the fruit names on column A and the formula on column C.

    At first, it just gave me a FORMULA PARSE ERROR, and I noticed that the very last mention of A2:A doesn’t light up in color like the rest of range references in the formula.

    I changed the commas in the formula for semicolons and it lit up but then the formula would show a #REF error with the message “RESULT WAS NOT AUTOMATICALLY EXPANDED, PLEASE INSERT MORE ROWS”….

    Do you have any suggestions?

    • Hi, Federico,

      The comma to semicolon issue is there because of the sheets locale settings (File menu > Spreadsheet settings). My sheets’ locale may be set to the UK and I assume yours are set to one of the EU countries.

      How to Change a Non-Regional Google Sheets Formula

      Regarding the problem, I have later written one more detailed tutorial on the same topic which contains a more simple formula using COUNTIF.

      Just search the keyword “running count” to find the tutorial. The search field is available on the top navigation bar.

      If that doesn’t solve your problem, feel free to share your sheet with me. I’ll try to sort out the issue for you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.