4.8/5
Home

Integrations

Plug Count neatly into your existing data infrastructure

For data teams

Collaborative, AI-driven data exploration and modelling

For product & growth

Faster access to the answers which matter

For leaders

Turning data into an engine of improvement

Pricing

Latest post

Meet the new Count Agent

Meet the new Count Agent

Docs

Guides, references, and API docs

Blog

Opinions, analysis, and the occasional uncomfortable truth about data.

Webinars

Join our experts for deep dives into data analytics and business intelligence

Gallery

Browse ready-to-use canvas templates and try them instantly

Sign in

Where to begin?

Start for free

Spin up a canvas and explore your data — a couple of clicks, no card.

Book a demo

See it live. Bring your questions — we’ll bring the answers.

Still not sure?

Send us a note — we’ll point you the right way.

Data to decisions, faster.

Compare

  • Count vs BI
  • Count vs Notebooks
  • Count vs Chatbots
  • Count vs Hex
  • Count vs Looker
  • Count vs Tableau
  • Count vs Thoughtspot

Learn

  • Blog
  • Webinars
  • SQL tutorials

Legal & security

  • Privacy Policy
  • Terms of Use
  • Cookies Policy
  • Trust Center
  • Security

Social

  • LinkedIn →
  • YouTube →
  • X →

Start with the hard question.

Ask Count anything — we’ll take you straight into a canvas.

Opens sign-up with your prompt ready for Count.

© 2026 Count Technologies Ltd. All rights reserved.

Careers →Book a Demo →
count

SQL Resources

Count is the best SQL IDE, wrapped up in the best data analysis tool, all inside the best BI platform.

ARRAY_AGG
Arrays Explained
Arrays Explained
CASE
CAST
COALESCE
DefinitionPractical InfoCommon QuestionsTroubleshooting Common ErrorsRelated Pages
CONCAT
COUNT [DISTINCT]
CURRENT_DATE
CURRENT_DATETIME
CURRENT_TIMESTAMP
DATETIME_DIFF
DATETIME_TRUNC
DATE_DIFF
DATE_TRUNC
Data Types
Dates and Times
EXTRACT
IF
MEDIAN
SUBSTR
String Functions Explained
TIMESTAMP_DIFF
TIMESTAMP_TRUNC
TIME_DIFF
TIME_TRUNC
UNNEST
Window Functions Explained
SQL Resources/BigQuery Standard SQL/COALESCE

COALESCE

COALESCE function. Definition, syntax, examples and common errors using BigQuery Standard SQL. The COALESCE function will return the first non-NULL expression.

Definition

The COALESCE function in BigQuery will return the first non-NULL expression. It's often used to safely handle NULL values.

Returns: Supertype of expr

coalesced
A

Practical Info

  • Often used similarly to IFNULL

Common Questions

How do I include NULL values in my aggregations?

In this case if you want to include NULL values in your aggregations, like AVG, you can use COALESCE to convert any nulls to a number. In this column, we convert all NULL values to 1 before taking the SUM so the NULL row is included in customers but not in normal_sum.

customersnormal_sum
0.333333333333333370.5

In this case the result of the AVG of the same column is different whether the NULL row is included as a 0 or not included at all.

How to JOIN 2 tables with COALESCE?

Let's say you want to join 2 tables, and if you can you want to join on user_id, but if the user_id is null you want to join on the name. You can use COALESCE to help with that!

user_idname
1Dave
nullNancy
2Bob
user_idnamescore
1Dave87
nullNancy92
user_idnameuser_id_1name_1score
1Dave1Dave87
nullNancynullNancy92
2Bobnullnullnull
ℹ️

Note - the join columns have to be the same type. In this case we casted our user_id to a string to make it compatible with the name column.

Troubleshooting Common Errors

No matching signature for function COALESCE for argument types. Supported signature: COALESCE([ANY, ...])

This error happens when BigQuery encounters different data types. Since it needs to create a column of a single type, it will error if it sometimes evaluates to a STRING and sometimes an INT64.

To resolve this use CAST to ensure your COALESCE parameters are all of the correct type.

COALESCE(expr[, ...])

Related Pages

  • Data Types in Standard SQL
SELECT
  COALESCE(NULL, 'A', 'B') AS coalesced
SELECT
  AVG(COALESCE(is_customer, 0)) AS customers,
  AVG(is_customer) AS normal_sum
FROM
  (
    SELECT
      1 AS is_customer
    UNION ALL
(    SELECT
      NULL AS is_customer)
    UNION ALL
(    SELECT
      0 AS is_customer)
  ) AS table_3
with table1 as (
  SELECT
  1 AS user_id,
  'Dave' AS name
UNION ALL
(SELECT
  NULL AS user_id,
  'Nancy' AS name)
UNION ALL
(SELECT
  2 AS user_id,
  'Bob' AS name)
),
table2 as (SELECT
  1 AS user_id,
  'Dave' AS name,
  87 AS score
UNION ALL
(SELECT
  NULL AS user_id,
  'Nancy' AS name,
  92 AS score))
SELECT
  *
FROM
  table1
  FULL OUTER JOIN table2 ON (COALESCE(CAST(table1.user_id AS STRING), table1.name) = COALESCE(CAST(table2.user_id AS STRING), table2.name))
SELECT
  *
FROM
  table1
FULL OUTER JOIN table2 ON (COALESCE(CAST(table1.user_id AS STRING), table1.name) = COALESCE(CAST(table2.user_id AS STRING), table2.name))

Got a CSV?
See it differently in <2 mins

Get started for FREEWatch our CEO do it