How To: Sorting Stacked Bars by Multiple Dimensions in Tableau

6/05/2016 Matt Chambers 4 Comments


For Makeover Monday, I wanted to tell the story of how Facebook is making an effort to make clean and renewable power its primary source of energy.  I wanted to be able to sort the stacked bars by energy usage percentage by year.  Here's how it's done:

1. Build your stacked bar chart in Tableau.


2. Create a combined field using the dimensions you want to sort by.  In this case, I want to sort by energy source by year.


3. Drag the combined field to the detail and sort by the measure.  Here I am sorting by the Amount.


4. Finally, drag the dimension that you are sorting by to the detail. I am using Energy Source in this example.


Now you have a stacked bar that is sorted by two dimensions.  In my example, it is sorted by energy source and date. This allows for some nice interactivity that allows you to show trends and magnitude simultaneously.  In my example, I am using it to show the rank of the energy sources while also showing the magnitude against other energy sources.


Please comment below with any questions or download the worbook to see how it's done.

4 comments:

  1. That's a great Tutorial sir.While practicing I also realised it will not work with Natural date heiarrachy like ( year,quarter,month) .Here,we need to take the Date( Date part( 'year',order Date)) then only it will work.Superb tutorial

    ReplyDelete
    Replies
    1. Thanks Rajeev! That's great to keep in mind.

      Delete
  2. Hi this is Rajeev
    I would like to add one more point - when you are creating a custom date calculation like DATEPART('year', [Order Date]) , make it sure to convert dimension into Attribute which is present in the color shelf . For example : Attr(Region)

    ReplyDelete

Note: Only a member of this blog may post a comment.