Reputation: 539
Let's say I have this simple data:
+-------+-------+---------+
| Tests | Names | Scores |
+-------+-------+---------+
| Test1 | John | 95 |
| Test1 | Becky | 90 |
| Test2 | John | 80 |
| Test2 | Becky | 85 |
+-------+-------+---------+
I want to write a calculated field that will return the name of the student of the highest score for each Exam. I want to do this without applying a filter to the whole chart.
Upvotes: 0
Views: 4713
Reputation: 539
The closest solution found was using a filter on the whole chart (https://community.tableau.com/message/443167#443167). With some modification, I was able to build and avoid applying the filter:
Here's the solution I came up with. It's 2 steps:
Step #1: Create a Calculated Field that is a Dimension to act as a filter. This filter will be true when the Student has the highest score.
Filter: [Scores] = {FIXED [Tests] : MAX([Scores])}
Step #2: Create a Calculated Field that is a Measurement to return the name of the student when the filter is true.
TopStudent: attr(if [Fan] then [Name] END)
ATTR will get rid of the NULLs.
(Edit: ATTR() returns the single unique non-null value if there is one, otherwise it displays a "*" to indicate that there are multiple values. So if more than one student got the same highest score, ATTR() will display a "*". If you want to show a single student name in the case of ties, you need a tie breaking rule -- for instance, use MIN() or MAX() instead of ATTR() to pick among the winners alphabetically.)
Now you can use this measurement to create a chart, showing the top student, without applying a filter to the whole chart.
Upvotes: 3