Imagine you have a Google Sheet tab containing a course worth of hundreds of students sorted into classes or groups. After each exam, quiz or assignment, your teacher for each class needs to enter in the grades.
To make life easier for your teachers, we want to create a summary page where we can click on their class and be navigated directly to their group.
We don’t want to have to manually create a link for each location so we are going to write a formula to do the work for us.
Now, the formula is a little complex. So first off, we will generate our list of classes and add a separate section start link for each one. Then we will combine the two together to generate a single formula that gets all the unique sections and provides a link for each one.
If you are playing along, you can grab a copy of the starter sheet here:
Working with IMPORTRANGE data in Google Sheets can be a little tricky. It may feel at times that it does not play by the same rules as when you are building formulas with data in the same Google Sheet.
In this tutorial, we’ll go through two approaches to filtering and sorting your IMPORTRANGE data by using the FILTER and QUERY functions. We’ll run through some examples of each and look at some of their pros and cons.
Then, we’ll wrap things up with a walkthrough and example on how to build your very own dynamic data dropdown dashboard from IMPORTRANGE data that lets us look at a set of sales by any company from our imported data any sales rep that makes a sale to them.
I encourage you to play along with the examples. You can find a copy of the Google Sheet that we will be importing here:
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…
In our example, we have a survey item asking quite humbly and without any leading statements 🐐😇:
How awesome are goats?
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.
Here is a link to the raw Google Sheet data I am using in the example so that you can play along.
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:
Get the count of the times the value appears in the range.
Get the total count of all the values in the range.
Divide the value count by the total count.
Change the result to be displayed as a percentage.
In our example, we want to humbly look for all the A’s, because 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:
The range you want to find your values in.
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.
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:
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.
This will return a decimal value: 0.3888888889.
We can change this in our submenu by clicking the Percentage format symbol:
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:
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.
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:
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:
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:
Once you have dragged down your formula to accommodate all your values you should get something that looks a little like this:
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.
Add in the Total as a side header and get it to stand out to make it look pretty.
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:
Next, access the Pivot table by going to Insert > Pivot Tables. A popup window will appear containing:
The data range you selected.
A choice of where to insert your data.
Select > Existing Sheet.
A line with an example will appear.
Select the grid symbol on the far right.
Another pop-up window will appear. Here you can choose what cell you want to start your Pivot Table.
Select cell E3 and then hit, Okay. ( You can drag the pop-up to a different location if it is in the way)
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.
Take a look at the Pivot Table editor. Look at the Rows item, select Add and then selectChoice.
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:
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?
That’s it you are all done. The great news is that the pivot table will change as you change your data too.
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.
In this Google Sheet tutorial, we’ll go through the nuances of using sort. You’ll find out how to sort by the sheet tab and by a selected range. Then, we will show you how sort works with text numbers and a mix of the two before diving into how to sort by multiple columns.
If you are new to Google Sheets or spreadsheets in general. Skill up and get an advantage on your workmates and check out the video below.
If you want to learn more about Google Sheets hit the subscribe button in the video or on this site (top right!).