+ Reply to Thread
Results 1 to 19 of 19

Pivot table with multiple levels to sort by?

  1. #1
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Exclamation Pivot table with multiple levels to sort by?

    I have several categories of data to sort. I want to sort them within a pivot table.

    Categories to sort from in the report filter area at the top (names of fields changed to protect my company's privacy):

    1.) National managers
    2.) Regional managers
    3.) Local managers
    4.) Local sales firms
    5.) Local sales agents
    6.) Local plan customer service representatives.

    Then, there will be about ten row labels, displayed from left to right. Here's an example:

    REPORT FILTER 1
    REPORT FILTER 2
    REPORT FILTER 3
    REPORT FILTER 4
    REPORT FILTER 5
    REPORT FILTER 6

    ROW LABEL 1 ROW LABEL 2 ROW LABEL 3 ROW LABEL 4 ROW LABEL 5 ROW LABEL 6

    So this is what I want to be able to do:

    When you select a name from "report filter 1," (in this example "national managers," you then only see the plans overseen by regional managers managed by that national manager. if you go further and select report filter 3 (local managers), you only see the plans of that local manager. And so on.

    When you select, say, "National Manager A," "Regional Manager B," and "Local Manager C", you see in the pivot table below ONLY the plans that fit ALL THREE filters. You can then also use filters on the row labels to sort the data by, say, dollar amount or contract number (two of the row labels).


    I've been told this would be much easier in Access, but my boss is insistent I use Excel.

    Ideas? thanks for your help!

  2. #2
    Forum Contributor noboffinme's Avatar
    Join Date
    08-29-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2003/7/10/13/16/19
    Posts
    1,071

    Re: Pivot table with multiple levels to sort by?

    Can you post the file OR a close example of the file to work with? Thanks
    Remember you are unique, like everyone else

  3. #3
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    Here is an example. Obviously this is fake data :-)

    What I'd like to do is when you select "National Manager," you see only the regional managers under that national manager. When you select a regional manager, you see only the branch managers under that regional manager.

    Then, whatever you have selected in the report fields, you only see the contracts under those managers. Also, you should still be able to use filters to sort by total asset value, contract number, fee change percentage, etc.

    I hope that makes more sense.

    Thanks for helping!!
    Attached Files Attached Files

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Pivot table with multiple levels to sort by?

    Must the workbook remain as .xls? If you may use .xlsx and you have Excel 2010 or above you may use slicers for the filters which will be better.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  5. #5
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    I have never used slicers before. I do not know if I can save it as .xlsx. Can anyone with Excel 2010 do this? I do have Excel 2010. I read about slicers and thought that might be the solution, but when I tried to implement them I couldn't figure it out. Advice? Thanks!

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Pivot table with multiple levels to sort by?

    It will work for all 2010 except maybe Starter edition. The file will look like this one.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    That would definitely work! Is there a way, however, to keep the report filters as drop-down lists? If not that's OK- I do have leeway with the specific appearance of the pivot table- but since this is being used by hundreds of managers and agents across the US it would be better if it's in a drop-down list (in case they don't know how to clear filters in the slicers). Basically I need to make this as user-friendly as possible-- all those managers are going to use this to find and sort their specific plan data.

    Also, can you explan HOW you made these slicers, so I understand the process? Thanks so much!

  8. #8
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    Also, when I try to filter Total Asset Value, bond portion, stock portion, etc from largest to smallest, I am unable to do this. How might this be possible? They need to be able to sort their plans by specific dollar amount data. Thanks

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Pivot table with multiple levels to sort by?

    You may use report filters as before but the lists do not adjust to match other filters so you will see all items listed in the dropdown even if they will not apply for the filters already in place.

    I think however that you perhaps do not want a pivot table at all - you only require a table that may be filtered. A pivot table will not sort in the manner that you wish. Access will be much better for this, I think. If you must do this with Excel only you will require some code I think to make it user-friendly.

  10. #10
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    Can you explain how you did the slicers? Currently, I have a spreadsheet with filters, but I can also submit this to my boss as an alternative in case they like it better and think it will be user-friendly enough.

    The code required- I am assuming it would be too complicated to try on my own? I'm willing to learn if you think it's possible for someone who has never programmed (besides coding with HTML and JavaScript).

    Thanks

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Pivot table with multiple levels to sort by?

    I only saved your workbook in xlsx format and then reopened it to escape compatibility mode. Then select a cell within the pivot table and choose Insert - Slicer from the Ribbon, and select which fields you wish slicers for.

    The code required will depend on exactly what must be achieved. If you only wish three heading filters above your actual table of data - and remove the pivot table completely - I do not think it will be too hard. If you wish I will produce an example?

  12. #12
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    I did get as far as inserting the slicers, but couldn't figure out how to make them sort properly. Remember I've never used slivers before- could you be more specific in how you created them, and how you made them such that when you click on the national manager's name, for example, that you only see the district managers associated with that national manager, and when you select a branch manager, you only see the branch managers associated with that regional manager?

    As to the code, this is sample data-- There are actually six headings I need in the real spreadsheet (possibly seven), with differene names from these (the real titles are company-specific and I need to protect the company's privacy), and there are at least ten row headings in the actual table of data (ten pieces of data I want displayed when you select the district manager, regional manager, etc that you want).

    Also, it would be ideal that you also see the categories from the pivot table report filter headings (district manager, regional manager, etc) displayed below in the table alongside all the other ten pieces of data. So If you are looking at the plans of District Manager A/Regional manager A/Branch manager A (all selected), you still see that info down below in the table. Does that make sense? It's hard to explain I think.

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Pivot table with multiple levels to sort by?

    Slicers do this naturally. When you select an item in one slicer, the invalid items in the others will become disabled and gray. The problem with the filter dropdowns is that they do not do this - I do not know why because autofilter dropdowns can!

    What I will suggest is that you create a table of all the data with the columns you require, and leave some blank rows above this table. Now create a pivot table above this table using the three columns you wish to filter by, then you must decide if you will use Slicers or dropdowns. For dropdowns you must add these three fields to the report filter. You may then hide the data part of the table and use the Worksheet_PivotTableUpdate event to autofilter the table below. The code for this is quite straightforward - if you will record a macro while autofiltering you will see what I mean.

  14. #14
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    Your answer was very thorough, but as a beginner with slicers/pivot tables I have a few clarifying questions:

    1.) If I use slicers, are you saying I don't use any report filter headings at all? i.e. i don't have the District Manager, Regional Manager, and Branch Manager dragged into the report filter field in the field headings tool from the pivot table menu?

    2.) I've never used macros. I know the concept, but I've never tried them in practice.

    3.) Where do I find the "events?" I've never filtered by event.

    I think with these three questions addressed I can figure out how to do this.

    Thanks for being so thorough and helpful by the way!!

  15. #15
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Pivot table with multiple levels to sort by?

    1. You do not need the fields in the pivot table at all if you use slicers (but you may put them there if you wish to allow both options).
    2. Recording a macro is easy - there is a little icon in the status bar you may click to start/stop recording. Very good thing to learn!
    3. If you right-click the worksheet tab and select View Code, the VB Editor will open. The main code window will be blank but it has two dropdowns at the top of it. If you select 'Worksheet' from the dropdown on the left, the one on the right will populate with a list of available events. If you select PivotTableUpdate from this list, a blank event procedure will be created for you which will look like this:
    Please Login or Register  to view this content.
    Note: you may delete the Worksheet_SelectionChange event that was created when you clicked Worksheet in the left dropdown.

    Within this event procedure you may put the code to autofilter your table - so, if we assume your actual data table begins in row 20 with headers and that the filter columns are in A:C columns of the table:
    Please Login or Register  to view this content.
    This code assumes you do have the three report filters in the pivot table. It may need some refining to match you real layout of course.

  16. #16
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    Thanks! I look forward to trying this!! One more Q:

    If I have more than 3 headings (which I will), would I modify "For n = 1 to 3" to read "For n = 1 to 6" (for 6 headers?)


    I am so excited to try using code in Excel for the first time :-) Thanks for your patience and help with this! I'd like to learn to program in the near future, and this is nice practice

  17. #17
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Pivot table with multiple levels to sort by?

    No - this loop is only for the three columns that are filtered by the report filters of the pivot table. It will not matter how many additional columns there are in the data table - but there must be a completely empty row above it so that the CurrentRegion part of the code only includes the data table.

    You are welcome - it is nice for me to return some of what I have received from this forum.

  18. #18
    Registered User
    Join Date
    02-03-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Pivot table with multiple levels to sort by?

    Oh perhaps I didn't explain right. I will have more than three report filter columns. I.e. there are more kinds of managers than three managers. Either 6 or 7. So I'm wondering if I just change the "For n = 1 to 3" to "For n = 1 to 6" or "For n = 1 to 7" to fit the number of report filter columns I have?

    I am so thankful so far to the help from this forum- everyone seems wonderful, and the time questions are answered is so fast!

  19. #19
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Pivot table with multiple levels to sort by?

    In that case yes - change the loop to match the filters. These columns must be in same order at start of the data table as they appear in the pivot table.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. sorting pivot table in levels
    By RubiksCuber in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 01-27-2013, 07:05 PM
  2. Sort multiple row label in pivot table
    By madc0w in forum Excel General
    Replies: 3
    Last Post: 10-31-2010, 01:48 AM
  3. How to Sort Multiple Columns in a Pivot table
    By ramki in forum Excel General
    Replies: 1
    Last Post: 08-07-2009, 11:38 PM
  4. Can I create a dimension with undefined multiple levels, pivot table.
    By Roberto Hernández in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-31-2006, 02:40 AM
  5. [SOLVED] Pivot Table Hide Levels in VBA
    By Brett in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-02-2005, 12:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1