5 Replies Latest reply on Jul 21, 2016 8:59 AM by David Li

    Sorting segments in stacked bar graph

    Nushrat Jahan

      I'm trying to sort the segments in a stacked bar graph by descending value. Currently, the segments are ordered based on the arrangement in the legend. However, I want to disconnect those two. Each bar should have a different order based on the values of the individual segments.  I've included the viz link and a photo of what it looks like on my end.

      Stacked bar graph.PNG

      https://public.tableau.com/static/images/Ci/CityMappingProj_/Population/1.png

        • 1. Re: Sorting segments in stacked bar graph
          Luciano Vasconcelos

          It's no possible to see the field you drag in the color card, but it's just classify this field by measure value descendent.

          • 2. Re: Sorting segments in stacked bar graph
            Nushrat Jahan

            That sorts the legend in ascending or descending ABC order. I don't have an option for the individual values being sorted in that order. I have Measure Names in my color card.

            Color field.PNG

            • 3. Re: Sorting segments in stacked bar graph
              David Li

              Hi Nushrat, you won't be able to do this when you use Measure Values/Names like you're doing now. If you could break this down by a dimension instead of by different measures, you could create an extra level of detail to sort upon by combining the color mark dimension with the column dimension, so that each color/dimension intersection has its own key to sort on. But you won't be able to do it with Measure Names, since [Measure Names] can't be used in calculations.

              2 of 2 people found this helpful
              • 4. Re: Sorting segments in stacked bar graph
                Nushrat Jahan

                Thanks for letting me know. I'm fairly new to Tableau. Do you have any recommendations regarding how I could go about breaking it down by dimensions instead of measure?

                • 5. Re: Sorting segments in stacked bar graph
                  David Li

                  You're welcome! When you run into this issue, you usually have to reshape your data source before you can move forward.

                   

                  What you want to do when designing or reshaping data sources is to think about the data structure that makes Tableau happiest, which is a ledger-like structure where you don't have any pivoted columns. For instance, in this example, we don't want a different column (measure, in this case) for the total population of each ethnicity. We want one column that measures population; each ethnicity will have its own row per city instead. Whenever a measure field is specific to a particular item in a dimension, you have pivoted data, which can be annoying to use in Tableau. Luckily, Tableau 9+ has a feature that can help you unpivot Excel data: Pivot Data (from Columns to Rows)

                   

                  So, to recap, you don't want this:

                   

                  CityX PopulationY PopulationZ Population
                  Los Angeles100200300

                   

                  Instead, you want this:

                   

                  CityEthnicity
                  Population
                  Los AngelesX100
                  Los AngelesY200
                  Los AngelesZ300

                   

                  Once you've done this, you can simply drop the "Ethnicity" dimension pill onto columns to break down each city by ethnicity. Then, you can do what I mentioned before and create a calculation [City] + [Ethnicity] that's unique for each intersection of City and Ethnicity, and then sort on that.

                  1 of 1 people found this helpful