Skip to main content

Command Palette

Search for a command to run...

Using COUNTIF() in BigQuery

Updated
1 min read
Using COUNTIF() in BigQuery
C

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified

Happy weekend! Do you remember the good old COUNTIF from Excel?
When I was just starting out in Analytics and was working with spreadsheets, I would make heavy use of it.

Well, turns out we have something similar in BigQuery as well.

It's an aggregate function, counting only rows that fulfill a given condition, for example COUNTIF( a > 10 and b = 'text')

Of course, this would be pretty much the same as combining COUNT + CASE WHEN.

See a quick example below.

Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.

Practical SQL

Part 1 of 50

Short, practical posts on SQL and BigQuery — from core language features to advanced query patterns. A reference for data practitioners at every level.

More from this blog

D

Datawise — SQL, BigQuery & Python for Data Engineers

205 posts

Data Engineer with a passion for transforming complex data landscapes into insightful stories. Here on my blog, I share insights, challenges, and the ever-evolving dance of technology and business.