How to Fill Null Values in Tableau
Nothing brings data analysis to a screeching halt faster than running into unexpected gaps in your dataset. These pesky NULL values in Tableau can break your charts, skew your calculations, and hide the very insights you’re trying to find. This guide will walk you through several straightforward methods to find and handle NULLs, transforming incomplete data into clean, insightful dashboards.
What Are Null Values and Why Do They Matter?
In the world of data, a "Null" value simply means that a value is missing or unknown. It’s not the same as zero or an empty text string (""). It's a blank space, an absence of information. For example, a "Sales" column in your dataset might be null for a specific day because no sales were recorded, or perhaps because of an error in the data entry process.
While seemingly harmless, nulls can cause significant problems in Tableau:
- Broken Visualizations: In a line chart that tracks daily visitors, a null value for a particular day will create a visible gap in the line, making it difficult to analyze trends over time.
- Inaccurate Calculations: Most calculations involving a null value will result in null. If you’re trying to calculate
[Profit] / [Sales]and[Sales]is null for a given row, the result will also be null, throwing off your overall analysis. - Skewed Aggregations: Functions that aggregate data, like
AVG(),SUM(), andCOUNT(), can produce misleading results. For example,AVG([Sales])will ignore null values entirely, calculating the average based only on the rows that contain data. This might artificially inflate your average sales if days with zero sales are simply recorded as nulls.
Effectively handling these gaps is a fundamental skill for creating reliable and accurate reports.
How to Find Null Values in Your Data
Before you can fix the problem, you need to identify where the nulls are hiding. Tableau provides a few easy ways to find them.
The "Indicator" Method
The simplest way to spot nulls is by looking for the small gray "X null" indicator in the bottom right corner of your view. When you drag a dimension or measure into your view (for example, building a table), this indicator will pop up if any null values are present in the fields you're using. Clicking on it gives you options for filtering or showing the data in the default position.
Using a Calculated Field to Count Nulls
For a more systematic approach, you can create a calculated field to specifically count how many nulls exist in a field. This is very useful for assessing the scale of the problem.
- Right-click on any empty space in the Data pane on the left and select
Create Calculated Field. - Name your calculation something descriptive, like
Count of Null States. - Use the
ISNULL()function in a formula. TheISNULL()function returnsTrueif a value is null andFalseif it is not.
SUM(IIF(ISNULL([State]), 1, 0))- Click
OK.
This formula checks each row in the [State] field. If it finds a null value, it assigns it a 1, otherwise, it assigns a 0. The SUM() function then totals up all the 1s, giving you a precise count of rows with null states. You can now use this new measure like any other, putting it onto a text card to see the total count.
Four Methods to Fill Null Values in Tableau
Once you’ve identified your nulls, you have several options for dealing with them. The right method depends on the type of data you have (a number or text) and what you want to achieve with your visualization.
Method 1: The ZN() Function for Numbers
The ZN() function stands for "Zero Null." As its name suggests, it is specifically designed to replace null numerical values with a zero. It's the quickest and cleanest way to handle fields where a missing value logically means a value of zero.
When to use it:
This is perfect for measures like sales, profit, or website sessions, where an absence of data can be treated as zero activity.
How to use it:
Instead of using your original measure field, create a calculated field that wraps it in the ZN() function.
- Create a new calculated field and name it (e.g.,
Sales (Clean)). - Enter the following formula:
ZN([Sales])- Click
OK. - Now, use
Sales (Clean)in your visualizations instead of the original[Sales]field. All null values will now appear as 0.
The great thing about ZN() is its simplicity, but remember it only works with numeric fields.
Method 2: The IFNULL() Function for Any Data Type
The IFNULL() function is more versatile and is your best choice when you need more flexibility than ZN() offers. It checks a field for nulls and allows you to replace them with any value you specify, whether it's a zero, another number, a calculated value, or even a text string.
The syntax is: IFNULL([Field to Check], [Replacement Value])
When to use it:
- Dealing with nulls in dimension fields (text). For example, replacing a null
[Region]with "Unknown." - Replacing null numbers with something other than zero, like the average value for that field.
How to use an IFNULL() for a dimension:
- Create a new calculated field and name it (e.g.,
Region (Clean)). - Enter the formula to replace any null values with a descriptive placeholder:
IFNULL([Region], "Unknown Region")- Use this new
Region (Clean)field in your worksheets.
How to use an IFNULL() for a measure:
- Create a new calculated field (e.g.,
Profit (Filled)). - You could simply replace nulls with zero, just like
ZN():
IFNULL([Profit], 0)- More powerfully, you can replace a null with a dynamic value, such as the average profit across the data. This requires a table calculation:
IFNULL(SUM([Profit]), WINDOW_AVG(SUM([Profit])))This allows you to fill gaps without bringing down the overall mean.
Method 3: Formatting to Connect Gaps in Charts
Sometimes, your goal isn't to change the underlying data but simply to fix a visual gap in a chart, like a line chart. Tableau has a built-in formatting option specifically for this purpose.
When to use it:
Ideal for time-series data displayed as a line or area chart where a few missing data points break the visual flow of the trend line. This method does not change the data, it only changes how it is displayed.
How to use it:
- Let’s say you have a line chart with a continuous Date field on the Columns shelf and a measure with null values (e.g.,
SUM([Users])) on the Rows shelf. You'll see gaps in the line where the data is null. - Right-click the green measure pill (
SUM([Users])) on the Rows shelf. - From the menu, select
Format. - A formatting pane will open on the left. Stay on the
Panetab. - At the bottom of this tab, you will see a section called
Special Values. - For the
Marksoption, click the dropdown menu (it usually defaults to "Show at Indicator"). Here, you can choose how to handle the special (null) values: - Choosing "Connect Lines" draws a line across the gap, creating a continuous, easy-to-read trend line without you having to write a single calculation.
Method 4: Using Table Calculations to Carry Values Forward
For more advanced scenarios, especially in tables, you might need to fill nulls with the last known, non-null value. This is a common requirement when working with data where values are only recorded when they change (e.g., inventory counts, status updates).
When to use it:
Use this when you want to propagate the previous non-null value forward to fill the following nulls. This is perfect for showing a running balance or maintaining a status over time until a new one is recorded.
How to use PREVIOUS_VALUE():
- Create a calculated field. Let's call it
Inventory (Forward Fill). - Enter the following logic. This formula tells Tableau: "If the current inventory value is null, then give me the value from the previous row. Otherwise, just give me the current inventory value."
IF ISNULL(SUM([Inventory Count])) THEN
PREVIOUS_VALUE(SUM([Inventory Count]))
ELSE
SUM([Inventory Count])
END- Add this calculated field to your table.
- Because this is a table calculation, you need to tell Tableau how to compute it. Right-click the new field pill in your view, select
Edit Table Calculation, and choose how it should be computed (e.g.,Table (Down)if you want to fill values down a single column).
This powerful function transforms a sparse table into a fully populated one, making it much easier to read and analyze.
Final Thoughts
Learning how to handle null values moves your Tableau skills from basic to intermediate. By using simple functions like ZN() and IFNULL(), leveraging formatting options for visual cleanup, or applying table calculations like PREVIOUS_VALUE() for more complex scenarios, you can turn messy, incomplete datasets into accurate and reliable dashboards that tell a true story.
The process of cleaning data, building calculations, and configuring visualizations in tools like Tableau is exactly what data analysis has always been about, but it’s often what keeps teams stuck. With so much time spent on the technical setup, less time is spent on strategy. We built Graphed to short-circuit that entire process. By connecting directly to your data sources and letting you use natural language to build your dashboards, we turn hours of manual setup into a 30-second conversation, letting you and your team focus on insights, not on figuring out formatting hurdles.
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!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.