Tableau ATTR() Function Explained with Examples

The ATTR() function in Tableau is one of the most important and commonly used functions, especially when you are working with dashboards, calculations, and aggregated data.

Many beginners get confused when they see an asterisk () in their visualization or when Tableau automatically converts a field into ATTR().

While building a sales dashboard in Tableau, I wanted to display the region name in the worksheet title. But the issue was, when multiple regions were selected, Tableau started showing an asterisk (*) instead of the name.

As a solution, I created a formula field using the ATTR() function in Tableau. This function helps to display a dimension value that might have multiple possible values within the view.

In this Tableau tutorial, I’ll explain what the ATTR function is and how to use it with practical examples.

What is ATTR() Function in Tableau?

The ATTR() function stands for the Attribute function. This function returns the value of the given expression if it has a single value for all rows in the group. If it has multiple different values, then it displays an asterisk (*).

Syntax to use the ATTR () function in Tableau.

ATTR(expression)

Here, the expression can be any dimension field, such as Region, Customer Name, or City. When Tableau processes this function, it applies a simple logic:

  • If there is only one unique value → return that value
  • If there are multiple values → return “*.”

This logic is widely accepted and even explained in technical discussions, where ATTR() is described as returning a value only if it is unique, otherwise returning an asterisk

For example, if we use the ATTR() function with the Region as below.

ATTR([Region])

In this calculation, if all records in the view belong to the same region, then it shows that region name; otherwise, it shows an asterisk (*).

Why is the ATTR () Function Important?

The ATTR() function is important because it helps maintain data accuracy and consistency in your dashboards. Without this function, Tableau might display incorrect values when multiple records exist.

For example, if you use MIN(Region), Tableau will show the first region value even if multiple regions are present, which is misleading. ATTR() avoids this problem by clearly indicating multiple values with an asterisk.

Another reason why ATTR() is important is that it helps resolve aggregation errors. Many beginners face errors like:

“Cannot mix aggregate and non-aggregate arguments”

This happens when you try to use a dimension with an aggregated measure. ATTR() fixes this by converting the dimension into an aggregated value, allowing the calculation to work correctly.

Use the Attribute(ATTR) Function in Tableau

In the examples below, I will explain the use of the ATTR() function in Tableau across different scenarios.

Example 1: Use the ATTR() Function to Show Sales for Each Customer

In this example, we will use the ATTR() function to display sales for a single customer’s purchase. If multiple customers purchase the product, it will display an asterisk (*).

Now, connect Tableau to the Superstore dataset and follow the steps below.

  1. Add the Product Name to the Columns and Sales to the Text card in the Marks section.
ATTR function in Tableau
  1. To create a calculated field, click on the Analysis tab and select Create calculated field.
Show NULL values using ATTR function in Tableau
  1. In this formula, we will use the ATTR() function to display the names of customers who purchased only one product.
ATTR([Customer Name])

With this formula, if two customers purchase any product, the ATTR() function will display the customer name (*) for those products.

  1. Now, add the ATTR calculated field to the Rows. With this, we can see if the customer name values are multiple for a product; if so, it is shown as (*).
Tableau ATTR function

If we use the Customer Name directly without the ATTR() function, all customer names will be displayed for each product.

Tableau Attribute function

This way, we can use the ATTR() function in Tableau to display a single value only when all rows have the same value.

Example 2: Using the ATTR( ) Function To Find Cities With the Same Name

In this example, we will create a text table to show sales by city for different states. In the USA, there are a few cities with similar names. Here, using the ATTR() function, we will highlight those cities by displaying their names in (*).

Using the ATTR() function, we will display the city name if it has only one state associated with it. If multiple states are there, then show *.

  1. To create the view, add the City to Rows and Sales to the Text card in the Marks section.
  1. To create a calculated field, click on the Analysis tab ->Create Calculated Field.
  1. Enter the formula below using the ATTR() function. This will display the city name only if it belongs to a single state. If it belongs to multiple states, then it will display (*).
ATTR([State/Province])
  1. Now, add the calculated field to the Rows along with the City. With this, we can see the ‘*‘ for the city names that are in more than one state.
Use ATTR function in Tableau

If we had used the States instead of the ATTR() field, the table would have displayed cities with multiple names, as shown in the image below.

Attribute function in Tableau

This way, we can use the ATTR() function in Tableau to identify rows with multiple values.

Error: Calculated Field Returning NULL Values after Using ATTR()

One common issue with ATTR is that it can return null values when used incorrectly in aggregation logic.

I was trying to create a calculated field from two values that I have. When I first tried to do the calculation, I received an error that I cannot mix aggregate and non-aggregate comparisons in an IF expression.

So I tried to use ATTR to fix this issue. The calculation is accepted, but all the values are now null.

Calculated field:

IF (ATTR([Region]) = "East") THEN AVG([Sales]) END

The issue is that after using the ATTR(), all results turn NULL. We are getting NULL values for the following reasons.

  • ATTR([Region]) only returns a single value if all records in the current partition have the same region.
  • If there are multiple regions, like East and West, then ATTR returns *.
  • Since * doesn’t equal “East”, the condition fails, and Tableau returns NULL.

There are now two ways we can fix this error.

Solution 1: Use Aggregations on Both Sides

In this method, we will make both fields in the calculation at the aggregate level.

  1. To create the view, add Sales to Text and Region to Rows.
  2. Create a calculated field, using the formula below.
IF MAX([Region]) = "East" THEN AVG([Sales Rate]) END
  1. Now, add the calculated field to the Tooltip in the Marks section.
ATTR Function NULL Error

This ensures Tableau uses aggregation and avoids the NULL output. With this, we can avoid showing null values in Tableau calculations.

Solution 2: Use Logical Condition with ATTR Handling

If you want to keep the ATTR() in the calculation and avoid NULL values, we can define custom logic using the ATTR() function.

  1. To create the view, add ‘Sales’ to Text and ‘Category, Region‘ to Rows.
  2. Create a calculated field using the formula below.
IF ATTR([Region]) = "East" THEN AVG([Sales Rate])
ELSEIF ATTR([Region]) = "*" THEN NULL
END
  1. Now, add the calculated field to the Tooltip in the Marks section.
Tableau ATTR Function NULL Values

However, this still won’t return a value if the partition includes multiple regions, and it also won’t show NULL values.

This way, we can resolve the NULL value issue in the Tableau ATTR() function.

In Tableau calculations, always use true aggregations (like MIN, MAX, or AVG) for comparison-based calculations. If you see ‘NULL‘ after adding ATTR, it usually means that the partition or row contains multiple values.

Frequently Asked Questions

Q1: What does ATTR() mean in Tableau?

It means Attribute function, used to return a value if unique, otherwise “*”.

Q2: Why does ATTR() show *?

Because multiple values exist in that field.

Q3: Is ATTR() an aggregation function?

Yes, it is an aggregation function for dimensions.

Q4: Can we replace ATTR() with MIN() or MAX()?

Technically yes, but it may give incorrect results.

Conclusion

The ATTR() function in Tableau is a powerful and essential function that helps maintain data accuracy in visualizations.

It ensures that only correct and meaningful values are displayed, and it prevents misleading information when multiple values exist. By understanding how ATTR() works, you can build better dashboards, fix aggregation errors, and improve your overall data analysis skills.

Whether you are a beginner or an experienced user, mastering the ATTR() function will help you create more reliable and professional Tableau reports.

You may also like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.