# Using COUNTIF() in BigQuery

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.

```sql
SELECT

  country,
  COUNTIF(Salary > 80000)  AS count_salaries_over_80k

FROM `learning.Customers`

GROUP BY country
```

![BigQuery results: count\_salaries\_over\_80k is 1 for CA, 0 for IT, 1 for UK and 0 for FR.](https://datawise.dev/images/using-countif-in-bigquery/1-result.jpg)
