ATTR() – Tableau’s Attribute Function Explained

Data

ATTR() – Tableau’s Attribute Function Explained

by Tim Costello
//

I have a love / hate relationship with the Attribute function in Tableau. I love it for what it does, I hate it for those times that someone asks me to describe what it does. It took me a long time to wrap my head around what ATTR() does in Tableau.

The first stop in my journey to understand the Attribute function was the Tableau online help. There, I found the following definition under ‘Aggregating Data’:  

Tableau's Attribute Formula

In Plain English

I found this to be useful, but I can see how non-developers might get lost in this formula. My next step to crack this code was to reach out to my team. James Wright offered this definition: 

“Attribute is a test for heterogeneity across the rows in the result set or homogeneity, depending on your perspective. Does every row have the same value? If so, value. If not, *.”

I LOVE this definition, but as Rob Austin in our UK office pointed out, it could possibly benefit from some simplification. Here’s how Rob defines Attribute.

“It returns a value if it is unique, else it returns *.”

I found this to be a great definition and very close to the one found in the Calculated Field Editor.  

ATTR Expression

ATTR() in Action

Let’s take a look at some data in Tableau and see if we can make sense of what’s going on based on these four ways of defining Attribute. In the following screenshot, I’ve created a simple crosstab showing the sum of Sales by City and State.

Simple Crosstab

Now, let’s apply the Attribute function to the State dimension.

Calculated Field [ATTR State]

Replace the State pill in our view with the ATTR State pill (from the Measures shelf).

Replace State Pill

What was the result of this change?  

ATTR Before and After

In the “Before” version of our table, we see all three states associated with Albany, one state each for Albemarle and Albuquerque, and two states for Alexandria. When we apply the attribute function to State we see the value of State returned where there was only one possible value (Albemarle, Albuquerque, Allen) and a star (*) returned where there was more than one possible value.

An Explanation

The way I look at this, Tableau is aggregating on the State value and showing us the state when it can: when the min(State) = max(State). In other words, there is only one possible value for State associated with a given city. If there is more than one possible value, it returns the *. I read the * as Tableau’s way of saying, “Hey, I see more than one of this thing, so I’ll show you an asterisk as my way of saying ‘more than one.’” One thing worth noting, the sum of Sales was correct in each instance.  

That’s not all there is to this story, I’ll dive even deeper into this puzzle in my next post!

More About the Author

Tim Costello

Analytics Consultant
3 Reasons Why You Should Want a Data Warehouse I hear a lot of reasons people avoid a data warehouse: It takes too long to build, data warehouse projects are expensive and often end ...
My Speaker Idol Talk from SQL PASS Summit 2014 Tim Costello shares his Speaker Idol talk from SQL PASS Summit 2014. Speaker Idol is a speaking contest among 12 of the sharpest SQL ...

See more from this author →

InterWorks uses cookies to allow us to better understand how the site is used. By continuing to use this site, you consent to this policy. Review Policy OK

×

Interworks GmbH
Ratinger Straße 9
40213 Düsseldorf
Germany
Geschäftsführer: Mel Stephenson

Kontaktaufnahme: markus@interworks.eu
Telefon: +49 (0)211 5408 5301

Amtsgericht Düsseldorf HRB 79752
UstldNr: DE 313 353 072

×

Love our blog? You should see our emails. Sign up for our newsletter!