top of page
Bernard K

Using the ZN Function in Tableau


Using the ZN function in Tableau

The ZN function when used in a calculation returns the default values if it is not nulls, otherwise it returns zeros. In summary, we can say that we use the ZN function to replace null values with zeros within our computations.

Syntax

ZN (Expression) – this function returns the expression if its not null, otherwise returns zero.

For example

This sample dataset shows the sales for different products in different quarters.

sample dataset

If you were to compute the average sales per product, this is what you’ll get.

table computing average

(And the reason you’re getting such results - is because NULL values are ignored when computing the average)

But suppose instead, you want to replace the NULL values in your computations with zeros. You can do that using the ZN function as shown below.

ZN function calculation

Notice this calculation replaces NULLs with zeros as you can see when you view the data.

And now using this calculation to compute the average leaves us with.

(From the resulting view, you can see the difference between the two computations – as highlighted by the star shapes.)

Therefore, next time you need to convert a large list of nulls into zeros, don’t forget the ZN function.

Thank you for reading.

Commentaires


Blog.png
Black & white.jpg

About Me

More About the Author

Bernard K

Analytics Consultant | 3X Tableau Certified

Bernard is a data analytics consultant helping businesses reveal the true power of their data and bring clarity to their reporting dashboards. He loves building things and sharing knowledge on how to build dashboards that drive better outcomes.

Let’s discuss your data challenges! Let’s work together!

bottom of page