+ Reply to Thread
Results 1 to 9 of 9

Pivot Table: Two-column sort ?

  1. #1
    Registered User
    Join Date
    09-18-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    8

    Pivot Table: Two-column sort ?

    I need a multiple column sort for a pivot table:

    Count of Trade . Gender
    Trade .......... Male ... Female ...Grand Total

    Ag. Labourer ..... 57 ...................... 57
    Female Servant .............. 39 ........... 39
    Male Servant ..... 37 ...................... 37
    Farmer ........... 29 ........ 1 ........... 30
    [etc]


    The required sort order is Grand Total (large>small) then Trade (A>Z), which seems to suggest a calculated field concatenating the Grand Total & Trade values, but I have had no success so far (and despite buying the Excel 2016 Bible !)

    Any suggestions would be much appreciated.
    Last edited by Dave+; 09-20-2017 at 04:02 AM. Reason: correct Trade Z>A

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Pivot Table: Two-column sort ?

    I think this is about lack of understanding how sort works.

    If the first sort criterion is the number in the Grand Total column, then the data is sorted by Grand Total.

    Only if there are several rows where the Grand Total is the same, only then, can you apply a secondary sort order that then sorts all the duplicates total rows by the Trade. But if all the grand total values are different, the secondary sort order will never apply. The data is sorted by Grand total.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Pivot Table: Two-column sort ?

    Hi Dave and welcome to the forum,

    I always agree with Teylyn, but you might understand more about sorting by reading:

    http://www.contextures.com/excel-piv...e-sorting.html
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Registered User
    Join Date
    09-18-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    8

    Re: Pivot Table: Two-column sort ?

    Quote Originally Posted by teylyn View Post
    I think this is about lack of understanding how sort works... But if all the grand total values are different, the secondary sort order will never apply. The data is sorted by Grand total.
    Many thanks - the first premise is correct ! Also, the full pivot table does contain several rows which have the same grand total value, hence the requirement for a secondary sort.

    I had previously perused Contexture's 'Excel Pivot Table Sorting' page (thanks MarvinP), but still can't see an example which readily assists.

    Dave.

    PS I am struck by the ease with which Excel can handle primary/secondary sorting for simple (non-pivot) tables, in contrast to the same requirement with a pivot table, which seems markedly more difficult, esp. with a grand total column (vs FoxPro/DBASE, using INDEX).
    Last edited by Dave+; 09-20-2017 at 04:36 AM.

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pivot Table: Two-column sort ?

    Hi,

    I don't believe you can have an automatic sort on two columns- you need to sort the row field alphabetically first, then sort by the data field, which should leave the row field in alphabetical order where possible. However, you would need code to reset this after refreshing the pivot if you do not wish to do so manually.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Registered User
    Join Date
    09-18-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    8

    Re: Pivot Table: Two-column sort ?

    Quote Originally Posted by xlnitwit View Post
    ... you need to sort the row field alphabetically first, then sort by the data field, which should leave the row field in alphabetical order where possible ...
    Many thanks - just tried it, but unfortunately the A-Z (Trade) column seems to revert to 'non A-Z' (presumably the original order).

  7. #7
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pivot Table: Two-column sort ?

    Can you sort the data source first? It may make a difference.

  8. #8
    Registered User
    Join Date
    09-18-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    8

    Re: Pivot Table: Two-column sort ?

    Quote Originally Posted by xlnitwit View Post
    Can you sort the data source first ...
    Yes - but the source sheet is protected and displayed in a sequence which needs to be retained (for checking against the hard-copy source), so preferably not.
    Last edited by Dave+; 09-20-2017 at 06:46 AM.

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Pivot Table: Two-column sort ?

    Having just run a quick test with 4 rows of data, all with equal value, applying a sort by the value field resulted in a row order that was neither A-Z nor the order of the original data source. Hence, I suspect you might have to use code to analyse the data by value and alphabet and create an ordered listing, then clear the sort from the row field and apply a manual order based on the ordered listing.

+ 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. [SOLVED] Sort Pivot Table by Column Subtotal
    By Tayque_J_Holmes in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 04-20-2016, 02:08 PM
  2. Sort by multiple column criteria within a pivot table
    By kesienerth00 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 06-30-2015, 01:49 PM
  3. [SOLVED] Sort pivot table based on first column entry
    By Derek Cavanagh in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 11-20-2013, 12:01 AM
  4. VBA to Sort Pivot Table (Specific Column)
    By AHFoddeR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2013, 02:39 AM
  5. Replies: 0
    Last Post: 11-11-2011, 04:10 PM
  6. Replies: 0
    Last Post: 11-02-2011, 12:21 PM
  7. [SOLVED] Sort a Column of Dates in Pivot Table
    By Linny in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-22-2005, 09:05 PM

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