Search

How to Use the ATTR Function in Tableau & Two Use Cases

What is the use of the attr function in tableau in this example I have region on rows I’m going to show you two ways to use the attr function you can see that there is an east north south and west region if I change this to attr Ive by clicking attribute you’ll see I get this asterisks what attr does is test if there is only one value in the the field if there’s not it outputs an asterisks if I use att-r on something like country region let’s bring that in and change it to a TTR I get United States because the only possible value within country region is United States so the first way to use attr is to test if there’s only one possible value within your data a second way to use att-r is to get around aggregation issues so let’s remove both of these let’s add region back input sales onto text if I wrote an if statement I’m going to write if region equals East then sum of sales and I get an error I get cannot mix non-aggregate and agate comparisons within if statement you’ll get this a lot in Tableau because of the complexity of calculations I can fix this error by wrapping region in attrAttr is an aggregate function so it turns region into an Aggregate and you no longer have the error let’s click apply and drag this into the view and show what’s HappeningFor calculation 2 you can see that East is now showing the sum of sales and nothing else is showing sum of sales within this row attr of region is equals to East it can only ever be East within this row within this row region attr region can only ever be North so attr of region at this level is the same exact thing as region and you got around the aggregation issue and that’s two ways to use the attr function in Tableau hope this helps


8 views0 comments