1 of 1 people found this helpful
I believe your first question is: why does the color legend contain more labels than are shown on the view? The answer is: the view itself has not labeled all of the lines. In a couple cases, several lines are so close together that Tableau has only chosen to label one of them, because otherwise the labels would overlap. But there are 10 lines on the view, and the color legend shows all 10.
For your second question, I would ask instead: why not just change the label configuration instead of resorting to a table calculation?
Now… if you really want to know about your table calculation, the answer is: LAST() returns an offset from the current value in the calculation window to the last value in the window. If LAST() = 0, it means that this is the last value in the window. What the "calculation window" is depends on how the table calculation is configured. If it's configured for "Table (across)" for example, then LAST() = 0 when you're on the final point of your line chart — which is why you only get a label there.
The reason why you have to use ATTR() in conjunction with LAST() is because table calculations operate on aggregates. So, even though your [Top N states vs others] is actually a dimension, you have to aggregate it to use it in the table calculation. ATTR() is an aggregation that says, "If the value is the same for all contributing data points, return that value, otherwise return something that indicates multiple values". When you know the value will always be the same for your segmentation, then ATTR() = MIN() = MAX() and you can use any of them to aggregate your value.
Regarding my second question, your explanation was spot on! Thanks
Now, about my first question. You are right, I didn't explain myself right. But the issue remains. When I drag State to Label, the view becomes dense as ALL states are included. Why is this? Why doesn't it only label the states that are showing on the view? (maybe this is a small issue and I'm over-complicating it - sorry about that).
When you add a dimension to Label, it has the effect of segmenting your data. So suddenly, you will see a line for every single state. You need, rather, a calculated field that lumps all the states that aren't in the Top N into "Other".
Here's what I did in recreating your screenshot:
1. Create your Top N set. I called mine [Top 9 Customers by Sales]
2. Create a calculated field [State with Other]
3. Use [State with Other] for both the color and the label. (Configure the label to only apply to Line Ends, and only Label End of Line.)
Workbook attached (version 10.1.5).
Top-9-states_JC-10.1.5.twbx 1.2 MB