Thursday, June 22, 2023

Explain the Number Function ' ZN ' in Tableau with Example?

 In Tableau, the ZN function is a number function that stands for "Zero If Null." It is used to replace null values with zero (0) in a calculation or expression.

The syntax for the ZN function in Tableau is as follows:

ZN(expression)
  • expression represents the value or field that you want to evaluate and replace nulls with zero.

Here's an example to illustrate the usage of the ZN function in Tableau:

Suppose you have a dataset with a column called "Sales" that contains sales data, including some null values.

Sales
1000
2000
(null)
1500

To handle the null values in the "Sales" column and replace them with zero, you can use the ZN function in a calculated field:

  1. Right-click on a blank area in the "Data" pane in Tableau.
  2. Select "Create Calculated Field."
  3. In the formula editor, enter the following expression:
ZN([Sales])
  1. Click "OK" to create the calculated field.

The calculated field, which utilizes the ZN function, will replace null values with zero in the "Sales" column.

The resulting dataset will be as follows:

Sales
1000
2000
0
1500

In this example, the ZN function evaluates the expression [Sales] and replaces any null values with zero. As a result, the null value in the third row of the "Sales" column is replaced with zero.

The ZN function is commonly used when dealing with null values in calculations or aggregations. It ensures that calculations involving null values do not produce unexpected or undesired results by substituting nulls with zeros. By utilizing the ZN function in Tableau, you can handle null values in your data effectively and perform calculations seamlessly.

No comments:

Post a Comment

If you have any doubts. Please let me know

How can you create an alias for a table in a SQL query?

In SQL, you can create an alias for a table in a query to give the table a temporary, alternative name that you can use in the query. Table ...