How to Use IFNULL in Tableau

Cody Schneider7 min read

Seeing "null" values or blank spaces in your Tableau dashboard can be frustrating. Not only do they make your reports look unfinished, but they can also break your calculations and lead to skewed results. Luckily, Tableau has a simple and powerful function to fix this issue: IFNULL. This article shows you exactly how to use the IFNULL function to clean your data and make your visualizations clear, accurate, and professional.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

What Are Nulls and Why Do They Matter?

In data analysis, a "null" value simply means that data is missing or unknown. It’s important to remember that a null is not the same as zero or a blank text string (""). While zero is a specific numerical value and a blank string is a specific text value, a null represents the absence of any value whatsoever.

This might seem like a minor detail, but nulls can cause two major problems in your reports:

  • They look unprofessional. A table showing sales per region with blank spots for certain regions gives the impression that the report is broken or incomplete. It forces the viewer to guess whether the sales were zero or if the data failed to load.
  • They can break your calculations. This is the more serious issue. When you perform mathematical operations, Tableau often skips over null values. For instance, if you’re calculating the average sale price for ten products and two of them have null values, Tableau will calculate the average based on only the eight products with data. This can quietly inflate your averages and give you a misleading picture of performance.

Introducing the IFNULL Function in Tableau

The IFNULL function is a straightforward tool designed to handle these exact problems. It works by checking a field to see if it contains a null value. If it does, the function replaces the null with a value that you specify. If the field is not null, it leaves the existing value as is.

The syntax is simple and easy to remember:

IFNULL([Expression 1], [Expression 2])

Let's break that down:

  • [Expression 1]: This is the dimension, measure, or calculation you want to check for nulls. For example, this could be your [Sales] field.
  • [Expression 2]: This is the value you want to substitute if [Expression 1] is, in fact, null. This could be the number 0 or a text string like 'N/A'.

In plain English, the formula says: "Check this field. If it has a value, show it. If it’s null, show this other value instead."

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

A Step-by-Step Guide to Using IFNULL

Let's walk through a common scenario. Imagine you have a table showing the number of pageviews for different blog posts, but some new posts haven't recorded any views yet, so their data appears as a null. Here’s how to clean that up.

Step 1: Identify the Nulls

First, drag your [Blog Post Title] dimension to the Rows shelf and your [Pageviews] measure to the Text mark on the Marks card. You’ll see a table where some page view cells are completely blank. Those are your nulls.

Step 2: Create a Calculated Field

Now, we'll create a new field that uses the IFNULL function to replace those blanks.

  1. In the Data pane on the left, right-click anywhere and select Create Calculated Field.
  2. A new window will open. Give your field a clear and descriptive name, like “Pageviews (Cleaned)” or “Pageviews with Zeros.” This helps you remember what the field does later.

Step 3: Write the IFNULL Formula

In the formula editor box, type the following expression:

IFNULL([Pageviews], 0)

This formula tells Tableau to look at the [Pageviews] field. If it finds a value, it will use that value. If it finds a null, it will replace it with the number 0.

Once you’re done, click OK. You'll see your new "Pageviews (Cleaned)" field appear in the Data pane.

Step 4: Use Your New Field in the View

The final step is to swap the original field with your new, cleaner field. Drag the original [Pageviews] measure out of your view. Then, drag your newly created “Pageviews (Cleaned)” field into its place. Magically, all the blank spaces in your table will now be filled with zeros. Your data is now clean, accurate, and ready for further analysis.

More Practical Examples and Use Cases

While replacing null numbers with zero is the most frequent use for IFNULL, its versatility extends to other data types as well.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Replacing Null Text with a Placeholder String

Suppose you have a [Customer Feedback] field that is empty when a customer hasn't left a review. A blank cell can look awkward in a dashboard displaying customer details. You can use IFNULL to insert a descriptive placeholder.

Calculated Field Name: "Feedback Status"

Formula:

IFNULL([Customer Feedback], 'No Feedback Provided')

Now, instead of jarring empty spaces, your dashboard will show a clear, professional-looking status update for each customer.

Handling Null Dates

Date fields can also contain nulls. For example, a dataset of project tasks might have a [Completion Date] field that is null for tasks that are still in progress. You can use IFNULL to flag these tasks clearly.

Because you can't mix data types (a date and a text string) in one field, you first need to convert the date to a string. The formula would look like this:

Calculated Field Name: "Task Status"

Formula:

IFNULL(STR([Completion Date]), 'In Progress')

This formula converts all existing completion dates to strings and replaces any null "completion dates" with the words 'In Progress'.

Common Mistakes to Avoid

IFNULL is simple, but there are a couple of common pitfalls to watch out for.

1. Mismatched Data Types

Tableau requires both expressions in an IFNULL function to have the same data type. You cannot replace a number with text directly, or a date with a number. For instance, the following formula will produce an error:

// This will cause an error IFNULL([Sales], 'N/A')

The [Sales] field is a number, but 'N/A' is a string. To fix this, you must convert the number field to a string using the STR() function, as we did in the date example.

// This works IFNULL(STR([Sales]), 'N/A')

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

2. Confusing Nulls with Zeros or Empty Strings

Remember, IFNULL specifically targets null values. It will not affect fields that already contain a 0 or an empty text string (""). If your goal is to replace both nulls and empty strings, you might need a more complex IF statement, like:

IF ISNULL([Comments]) OR [Comments] = "" THEN "No Comment" ELSE [Comments] END

IFNULL vs. ZN() – What's the Difference?

As you get more familiar with Tableau, you might come across another function called ZN(). The ZN function, short for "Zero Null," is a specialized shortcut for handling numerical nulls.

The expression:

ZN([Sales])

is functionally identical to:

IFNULL([Sales], 0)

So which one should you use? Here’s a simple rule of thumb:

  • Use ZN() when your only goal is to quickly replace null numbers with a zero. It’s faster to type and makes your intention clear.
  • Use IFNULL() for all other situations: when you are working with text or date fields, or when you want to replace a numerical null with a value other than zero (for example, replacing it with the average of the column).

Final Thoughts

The IFNULL function is an essential tool for anyone working in Tableau. By mastering it, you can easily clean up messy data, ensure your calculations are accurate, and create dashboards that are both professional and easy to understand. It’s a simple function that delivers a massive impact on the quality of your reports.

Tidying up data is often the most time-consuming part of reporting, and functions like IFNULL are lifesavers. Still, the process of connecting to multiple platforms, cleaning data, and building reports from scratch is a huge time-sink. For those who want to skip the manual setup and get straight to answers, we built Graphed. It connects your data sources and allows you to create dashboards and reports in seconds using plain English, so you can focus on insights instead of data prep.

Related Articles

How to Enable Data Analysis in Excel

Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!