Skip to content

Tableau ATTR

  • by

1. Overview

In this article, we will explore the Tableau ATTR function followed by some limitations of it.

For this article, we will use the superstore sample data set provided by Tableau so everyone has access to it. In Tableau, ATTR() is a special function that stands for Attribute.

It is used to ensure that a field is consistent within a certain context or level of detail. It checks whether all the values in a field are the same across the data being aggregated. If they are, it returns that single value; if they are not, it returns a * (asterisk), showing that there is more than one distinct value.

2. Tableau ATTR

Calculation: You can understand the formula for ATTR() as:

IF MIN([Region]) = MAX([Region]) 
THEN MIN([Region])
ELSE "*" END

How ATTR() Works Internally:

  • Aggregation at the Current Level of Detail (LOD): Tableau first looks at the level of detail for the current view (the combination of dimensions in the rows, columns, filters, and other shelves). It examines the values for the specified field ([Field]) at that level of detail.
  • Check for Uniqueness: Tableau performs an aggregation across all data points in the current scope (defined by the view’s level of detail) by checking if:
    • MIN([Field]) equals MAX([Field]).
    • If they are the same, Tableau determines that there is only one unique value for that field at the current level of detail.
    • If the values differ, it concludes that there are multiple values and returns an asterisk (*).

2.1. Tableau ATTR Example:

If you have a data set with a field called Region and place it in a view with a different dimension (say Year), using ATTR([Region]) will return the region name if the region is consistent for all rows of data in the view. If, however, multiple regions exist for a particular year, Tableau will display *.

Formula:

IF ATTR([Region]) = "East" THEN "Eastern Region"
ELSEIF ATTR([Region]) = "West" THEN "Western Region"
ELSEIF ATTR([Region]) = "North" THEN "Northern Region"
ELSEIF ATTR([Region]) = "South" THEN "Southern Region"
ELSE "Other Region"
END

Here, the ATTR([Region]) will return the region name if there is only one unique value, else it will return *.

Tableau ATTR

Based on the output, this calculated field will display “Other Region” in case of * (multiple values).

Tableau ATTR

3. Common Use Cases for ATTR:

  • Non-Aggregated Fields in Aggregated Views: If you want to display a dimension in a view with all other aggregated fields, ATTR ensures that the dimension does not disrupt the aggregation.
  • Preventing Ambiguity: When you’re working with a field where you expect only one value in the current level of detail, ATTR helps ensure that there is no ambiguity by returning * if multiple values exist.
  • Avoiding Errors: When dragging a dimension onto the view, Tableau may default to the ATTR([Field]) instead of [Field] if it detects that the field could have more than one value in the current view for that field.
  • Comparison with Other Aggregations: Unlike SUM, AVG, or COUNT, ATTR does not summarize data but checks for consistency. If there’s only one value, it behaves like MIN, MAX, or a direct reference to the field. If there are multiple values, it returns *.
  • Handling Nulls: Tableau ATTR is sometimes useful when working with null values or when aggregating fields that can contain multiple values per level of detail.

4. Conclusion

You can use the Tableau ATTR in scenarios where it won’t make sense to have a strict aggregation but consistency in value display is still required.

In summary, Tableau ATTR is useful for dealing with fields that should typically have a single value at a certain level of detail, ensuring that Tableau doesn’t display erroneous or unexpected multiple values. To learn more about Tableau, refer to these articles.

Leave a Reply

Your email address will not be published. Required fields are marked *