Get the Occurrence of a Value in a Range as a Percentage in Google Sheets

Get the occurrence of a Value as a percentage in Google Sheets

Finding out how frequently something occurs compared to the rest of the data in a range is a pretty common task in Google Sheets. You will use it to find the frequency of grades in a grade book, the number of sales of an item compared to your total sales or the frequency of choices of a particular item in a survey.

In this tutorial, we will cover how to find the occurrence of a value in a range as a percentage in Google Sheets. I then show you how to do this quickly for all your values in a range as a set of formulas and as a pivot table.

Let’s get started…

The Example

In our example, we have a survey item asking quite humbly and without any leading statements 🐐😇:

How awesome are goats?

  • A: Great
  • B: Good
  • C: Okay
  • D: Meh
  • E: Jealousy is a curse

Then in column A, we have a list of respondents and, in column B, we have a list of responses or choices.

Example data for list of occurrences as a percentage in Google Sheets V2
Click to expand!

Here is a link to the raw Google Sheet data I am using in the example so that you can play along.

Get Occurrences as a Percentage – Worksheet

Just go to File > Make a copy. Then you have your own version to edit.

Get the Occurrence as a Percentage of a Single Value

To get the number of times a value occurs as a percentage of all the values in a list we will need to:

  1. Get the count of the times the value appears in the range.
  2. Get the total count of all the values in the range.
  3. Divide the value count by the total count.
  4. Change the result to be displayed as a percentage.

In our example, we want to humbly look for all the A’sbecause it is pretty clear that the survey is a shallow ruse to fish for compliments.

Our range of choices is from B3:B20.

Let’s break our formula down into manageable chunks.

Get the total count of all A’s

To get the total count of all the A’s in our range we can use the COUNTIF function. This function allows us to get the count of something based on a value.

It doesn’t have to be just A though. You could use this function to get the count of, say, the number of students who got higher than a grade in a particular test.

It’s a really useful function.

COUNTIF takes two arguments:

  1. The range you want to find your values in.
  2. The criterion you want to find to count.

=COUNTIF(Range to search, Criterion)

In our example, the range is column B and the criterion is A.

=COUNTIF(B3:B20,“A”)

For our example, this will return a value of 7.

Get the total count of all values in the range

Next, we need to get the total count of all the values in a range. We can’t use the traditional COUNT function here because COUNT only deals with numbers. Instead, we need to use COUNTA that counts any value that isn’t blank.

COUNTA can take a single range or multiple ranges. However, we only want to count our range of choices. Here is what it would look like:

=COUNTA(B3:B20)

Which will return a value of 18.

Dividing the value count by the range count

Next, we need to divide the value count by the range count.

=COUNTIF(B3:B20,“A”)/COUNTA(B3:B20)

This will return a decimal value: 0.3888888889.

We can change this in our submenu by clicking the Percentage format symbol:

Percentage Menu Item Google Sheets

This will result in 38.89%. Much lower than what is conscionably right and true. 🐐

Check out the short video demonstration:

Get the Percentage of Occurrences of Each Value in the Range with Formulas

Get the percentage of one value occurring in our range is fine, but often we need to get the percentage of all the values in a range.

I try and keep my data as dynamic as possible. This means that I want to create formulas that can update easily if changes are made to the data. So that the next time I have to do a similar task, I already have a working template ready to copy and paste into.

In this example, I will show you how to create a summary chart of all the values as a percentage.  Here is what our end result will look like:

percentage of occurrence of all values in a range in Google Sheets
Click to Expand!

If you are playing along, go to the next Google Sheets tab in the sample sheet named Range (formulas). 

Titles and subtitles

First, in column F3, paste in the header:  Occurrence of Choices as a percentage of all data. Format to taste.

Then in F4 and G4 add the sub-headers: Choice and Choice as % respectively.

Get a dynamic list of values

We could just list our values by hand but that doesn’t make a very good template. We can get a unique list of all of our choices by using the UNIQUE function in Google Sheets. UNIQUE takes a range of values.

=UNIQUE(B3:B20)

This won’t sort your choices alphabetically though. So let’s put our UNIQUE function inside a SORT function. The SORT function first takes the range you want to sort and then can take a number of optional arguments that we won’t use here.

Here is what our example will look like:

=SORT(UNIQUE(B3:B20))

SORT UNIQUE Google Sheets
Click to Expand!

Now we have a dynamic list of choices that will change automatically if our data changes. Sweet!

Getting the percentage of occurrences for each value

Now we can use our original formula to get the frequency of occurrence of each value in our Google Sheet. This time around I have made a few minor changes to the formula that you might miss at first glance:

=COUNTIF($B$3:$B$20,F5)/COUNTA($B$3:$B$20)

First of all, I have referenced the corresponding value cell on the left. In our first row, this is F5 or the value  “A”. Next, I have added dollar signs to my range to lock it in or make it absolute. Otherwise, the cell range would have moved down as I dragged my formula down each cell in the column causing and error in our count.

You can find out more about absolute and relative references in my post here:

How do I lock certain cells in a formula in Google Sheets?

Once you have dragged down your formula to accommodate all your values you should get something that looks a little like this:

Get the occurrences of each value in a range as a percentage in Google Sheets
Click to Expand!

Finishing up

Finally, we can add the total to the bottom, just in case someone doesn’t know that everything should equal 100%. Oh, and to check that we didn’t mess up.

You can simply do this with the SUM function. That will take the range or all the calculated percentages. If you are lucky, when you put in the equals sign, Google Sheets will suggest the calculation for you.

=SUM(G5:G9)

Add in the Total as a side header and get it to stand out to make it look pretty.

Sum of all occurrences of values as percentage in Google Sheets
Click to Expand!

Next, we will look at another way of achieving this that you might find easier or quicker.

Get the Percentage of Occurrences of Each Value in the Range with a Pivot Table

In this example, we are going to grab our occurrence percentages for each value using a pivot table. This can be a much quicker approach. Plus it has the added benefit of adjusting to the remaining values in a filter or a slicer.

Let’s get cracking!

If you are playing along, go to the next sheet tab named, Range (Pivot Table).

Pivot tables in Google Sheets allow you to analyse and transform data into interesting charts that allow you to quickly summarise your data.

Creating the pivot table

First, we will select our column of Choices. This time around, we will include the header:

B2:B20

Next, access the Pivot table by going to Data > Pivot Tables. A popup window will appear containing:

  1. The data range you selected.
  2. A choice of where to insert your data.
    1. Select > Existing Sheet.
    2. A line with an example will appear.
    3. Select the grid symbol on the far right.
Create a pivot table first popup window for frequency of values as a percentage in Google Sheets
Click to Expand!
    1. Another pop-up window will appear. Here you can choose what cell you want to start your Pivot Table.
    2. Select cell E3  and then hit, Okay. ( You can  drag the pop-up to a different location if it is in the way)
Selcte a location for a Pivot Table for a list of percentage of occurrences in Google Sheets
Click to Expand!
  1. Back in the original popup and click Okay. 

Creating your pivot table data

Once you hit okay, a Pivot Table editor in the sidebar would have appeared on the right. And a small template would have appeared starting in your selected cell.

Pivot Table Editor for frequency by percentage in Google Sheets
Click to Expand!

Take a look at the Pivot Table editor. Look at the Rows item, select Add and then select Choice.

You will get a little box with your Choice data.

Next, move down to Values and select Add. Again, select Choice. If you are lucky, Google Sheets would have added a count of all the values in the range. If not select the Summarized by dropdown and choose COUNTA.

At this stage, things should look like this:

Pivot Table of count of choices in Google Sheets
Click to Expand!

We’re almost there.

Next, under Values, select the Show as dropdown and select % of column. 

Bang! We did it! Go ahead and close the Pivot Table editor.

Now, to tidy up let’s change that verbose subheader with the COUNTA of blah…blah…

Click on cell F3, and enter “Choice as %”.

This is what it should look like now?

Pivot Table of Complete percentages of choices in Google Sheets
Click to Expand!

That’s it you are all done. The great news is that the pivot table will change as you change your data too.

Conclusion

We’ve covered how to get the frequency of a value occurring in a range by creating our custom formula. Then we have looked at how to make a dynamic summary of all the values as a percentage using formulas first and then as a pivot table.

So which one did you like the most the pivot table or the formulas to build the summary? Let me know in the comments below. I’d be interested to hear your thoughts.

Did you enjoy the tutorial? Want a solid step-by-step course to become a pro at Google Sheets? Check out my course, Google Sheets: Learn the Essentials with Three Detailed Projects. Sign up today.
Google Sheets Shortcuts Mousepad
Google Sheets Shortcuts Mousepad

Want a fast track to boost your Spreadsheet efficiency? Grab one of these handy Google Sheets Shortcuts mousepads that I created from my store.

Google Sheets Shortcuts Mousepad Gel
Google Sheets Shortcuts Mousepad Ge

~Yagi

2 thoughts on “Get the Occurrence of a Value in a Range as a Percentage in Google Sheets”

    1. Hi Sue,

      You could use this approach for a single value with the most occurrences:
      =INDEX(QUERY(A1:A30,”SELECT A, COUNT(A) GROUP BY A ORDER BY COUNT(A) DESC LIMIT 1″,0),2,2)

      Where A1:A30 would be your range of values.

      ~Yagi

Leave a Reply