3 Replies Latest reply on Mar 20, 2017 10:45 AM by Jamieson Christian

    Labeling issue

    Esther Twain

      Hello again, and happy international day of happiness


      This time I'm trying to show the cumulative sales across time of the top N states by sales VS. all other states, and also label the last point of each cumulative total with the state.


      This is the solution. See Caption on the right.1 (Superstore subset, version 10.2)


      labeling issue.PNG


      I understand everything until we get to the labeling of the marks.

      First, why putting state on Label labels EVERY single mark and not just the ones on the view?

      Second, in order to label it correctly we calculate this field: IF LAST()=0 THEN ATTR([Top N states vs others]) END. What do LAST() gives us and why ATTR?


      Thanks, fellow tableauers!



        • 1. Re: Labeling issue
          Jamieson Christian



          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.

          1 of 1 people found this helpful
          • 2. Re: Labeling issue
            Esther Twain

            Hey Jamieson,


            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).



            • 3. Re: Labeling issue
              Jamieson Christian



              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.)


              4. Voila!



              Workbook attached (version 10.1.5).

              1 of 1 people found this helpful