Documentation Data Pipeline FAQs

Include NULL values when applying functions in Data Explorer

If you have NULL values in your column, you won’t be able to perform functions on it or combine it with another column. NULL results will be ignored and excluded from your results. This is a result of what’s called three-value logic (3VL) in SQL. Please refer to the following page for a detailed explanation.

To get around this, you’d convert the NULL values to another value (such as 0) or to values from other columns using SQLite’s coalesce function or CASE statement.

Replacing NULL values with zero using coalesce

If you’d like to replace all NULL values in a column with another value, the coalesce function easily lets you do this. This function accepts two or more arguments and returns the first non-NULL argument; the function must have at least 2 arguments.

The basic format looks like this:

coalesce("column", replace_value, ...)

Parameters

column: The column containing the NULL values you want to replace with the specified replace_value.

replace_value: The column or values you want to replace your NULL values with. You can have more than one replace_value.

To replace NULL values with the coalesce() in the Data Pipeline, click +Add Transformation and choose Add Column from the menu options. To replace any column name that could contain NULL values with 0, use the following formula (replacing Column Name with the name of your column):

coalesce("Column Name", 0)

Coalesce query results

You’ll likely want to hide your original column by adding a Hide Columns step after the Add Column step in the Data Pipeline.

Tip! To minimize the number of Pipeline Actions, you can combine multiple functions in a single formula, as shown in the screenshot above.

Replacing NULL and blank values with a CASE statement

If coalesce() doesn’t fully replace all empty values in your query results, your result set may contain both NULL and blank values. To account for both cases, use a CASE statement instead of coalesce().

To do this, you can either use an Add Column or an Edit Column Pipeline step and follow these steps:

  1. Select the column to which you want to add zero fill.
  2. Select the formula type as Custom formula.
  3. Enter the following case statement in the Formula field (replacing Column Name with the name of your column):
case
	when "Column Name" is null then 0
	when "Column Name" = '' then 0
	else "Column Name"
end

Case statement to replace NULLs and blanks

Replacing NULL values using another column

You can also use coalesce() to replace NULL values found in one column with another column’s values. This would be carried out at the row level. For example, if column A’s value is NULL in row 3 and you want to replace that NULL value with a value from column B, the function would replace the NULL from column A with the value from column B in row 3.

coalesce("Column A", "Column B", ...)

Check out our step-by-step video showing how to do this: