How To: Sorting Stacked Bars by Multiple Dimensions in Tableau

6/05/2016 Matt Chambers 9 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.

9 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. Divine Loan Opportunity Offered By CHESTER BRIAN LOANS That Save My Family From Financial Bondage {Brianloancompany@yahoo.com }

      Hello Everyone, I am Rosie Rhoma a single mom from Texas USA, I will like to share this great testimony on how i got a loan from Chester Brian Loans, when we were driven out of our home when i couldn't pay my bills anymore, After been scammed by various companies online and denied a loan from my bank and some other credit union i visited. my children were taken by the foster care, i was all alone in the street. Until a day i shamefully walked into an old school mate who introduced me to Daisy Maureen. At first i told her that i am not ready to take any risk of requesting a loan online anymore, but she assured me that i will received my loan from them. On a second thought, due to my homelessness i had to take a trial and applied for the loan, luckily for me i received a loan of $80,000.00 from Chester Brian Loans. Am happy i took the risk and applied for the loan. my kids have been given back to me and now i own a home and a business of my own. All thanks and gratitude goes to CHESTER BRIAN LOAN COMPANY for giving a meaning to life when i had lost all hope. If you currently seeking for a loan assistance, you can contact them via: {Brianloancompany@yahoo.com } OR text (803) 373-2162 and also contact there webpage via brianloancompany.bravesites.com

      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
    Replies
    1. Thanks again! I'll keep this in mind.

      Delete
  3. Hello Matt!

    I am new with Tableau and I have a real problem to create parallel staked bars (one for each dimension) My dimensions are opinion scales (strongly agree, agree, neutral, disagree and strongly disagree).Dimensions are 1) I am happy at work 2) My work inspires me 3) I have fun at work, etc.

    ReplyDelete
    Replies
    1. Hi, to make this work, you will need to pivot your data:

      https://onlinehelp.tableau.com/current/pro/desktop/en-us/pivot.html

      Delete
  4. Great work Matt!
    I am trying to figure out a way of repositioning the selected energy source in the stacked bars. Would like to see it at bottom (i.e. with a fixed baseline) in order to properly assess the trend. Do you have any ideas on how that may be accomplished?

    ReplyDelete