Spreadsheets Tutorial: IF functions
Key Takeaways
This video tutorial by DataCamp covers the use of IF functions in spreadsheets, specifically the COUNTIF, AVERAGEIF, and SUMIF functions, to calculate summaries based on different groups of data.
Full Transcript
nice work summarizing the data you probably noticed that these summaries don't help us much yet they would be more useful if we could calculate summaries based on different groups of data such as by precinct or crime type in this video you will learn about functions that only include data if they meet certain conditions let's take a look to count the number of crimes by precinct or compute the average time by precinct we first need a list of all the possible values of that column this is a perfect use for the unique function it takes a set of data and returns an unduplicated list of the distinct values in the column for example calling the unique function on the C column will give you a list of all the precinct names in our data set listing each precinct only once now that you have a list of all possible values you can easily compute summary statistics for groups within the data set for example you might want to count the number of Records for each group such as the number of crimes by precinct you can use the countif function to do this it takes two arguments the range refers to the cells that you want to count and the criterion refers to the value that you want to count so you can use the unique list of precincts and the countif function to count the number of crimes per precinct you can also count the number of crimes that occurred after 8:00 o'clock by changing the criteria to all crimes with a time greater than 2000 recall that our data list times in 24-hour form we can also use the average if and some if functions to compute GroupWise summary statistics these functions take three arguments instead of the two required by count if they require a criteria range a criterion and arrange to which they apply the function for example you can calculate the average time at which a crime occurred by specifying the criterion range as the column that contains precinct names the criterion as the name of the precinct of interest and the column containing x as the range to which to apply the function similarly you can calculate the sum of crimes in various precincts by specifying the range of columns that contain precinct names the criterion to evaluate and the column containing counts of crimes in those precincts as the range to apply the sum function so that will help us improve the insights from our data but what if you want to restrict your counts averages or sums based on multiple criteria fortunately spreadsheets has functions that do just that let's start with the countifs function it takes a practically unlimited number of pairs of arguments that we typically provide no more than three criteria and it allows for multiple criteria you can even apply different criteria to the same range as you might need to if you only wanted to count crimes between 8:00 o'clock and midnight let's consider an example say you want to count the number of crimes in the West precinct that occurred after 8 o'clock in the evening you would call the countifs function specify the first range then the criteria to check then the second range and the criteria to check we can use the average ifs function similarly the order of the arguments in the average of this function is a bit different from that of countifs for example the first argument of average ifs is the range of cells to include in the average not the first criteria range it also takes pairs of ranges and criteria and allows for multiple criteria for the same range now you're armed with multiple functions for creating and counting groups of data let's get some
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/error-and-uncertainty-in-spreadsheets at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
Nice work summarizing the data. You probably noticed that these summaries don't help us much yet. They would be more useful if we could calculate summaries based on different groups of data, such as by precinct or crime type. In this video you will learn about functions that only include data IF they meet certain conditions. Let's take a look.
To count the number of crimes by precinct or compute the average time by precinct, we first need a list of all the possible values of that column.
This is a perfect use for the UNIQUE() function.
It takes a set of data and returns an unduplicated list of the distinct values in the column.
For example, calling the UNIQUE() function on the C column will give you a list of all the precinct names in our dataset, listing each precinct only once.
Now that you have a list of all possible values, you can easily compute summary statistics for groups within the dataset.
For example, you might want to count the number of records for each group, such as the number of crimes by precinct.
You can use the COUNTIF() function to do this. It takes two arguments: the range refers to the cells that you want to count, and the criterion refers to the value that you want to count.
So you can use the unique list of precincts and the COUNTIF() function to count the number of crimes per precinct.
You could also count the number of crimes that occurred after 8:00 by changing the criteria to all crimes with a time greater than 2000. Recall that our data list times in 24-hour format.
We can also use the AVERAGEIF() and SUMIF() functions to compute group-wise summary statistics. These functions take three arguments instead of the two required by COUNTIF():
They require a criteria range,
a criterion,
and a range to
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: Data Literacy
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
X now offers an MCP server to make its platform easier for AI tools to use
TechCrunch AI
n8n Automation Repurpose Video Content: The 2025 Production Guide
Dev.to AI
You’re Still Paying $200/Month for AI Tools You Could Replace With a Free Local Setup Tonight
Medium · Data Science
Top 10 AI Tools Every College Student Should Know in 2026
Medium · AI
🎓
Tutor Explanation
DeepCamp AI