Consulting

Results 1 to 5 of 5

Thread: pivot table - sort items with different order for each parent item

  1. #1
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    2
    Location

    pivot table - sort items with different order for each parent item

    My table looks like this
    P1 C1
    C2
    C3
    P2 C1
    C2
    C3

    I want it to look like this
    P1 C1
    C3
    C2
    P2 C1
    C2
    C3
    But if i change the position for P1 items it also changes for P2 and ends up like this
    P1 C1
    C3
    C2
    P2 C1
    C3
    C2
    Is there a way to achieve this? I want to do the sorting in VBA but even manually i cannot achieve what i want.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why would you need to do that? Surely, analysis means having the data to analyse, the order is not a data attribute.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Aug 2017
    Posts
    2
    Location
    Quote Originally Posted by xld View Post
    Why would you need to do that? Surely, analysis means having the data to analyse, the order is not a data attribute.
    I have many reports (done using many different tools) and i want to keep the same ordering in all the reports. That said the main reason is because my boss wants it like this.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by tjmtest View Post
    That said the main reason is because my boss wants it like this.
    The worst reason, but the most understandable .

    I can't see anything in pivots that would facilitate this, the only way I could think is to have a calculated column in the original data that holds an index that gives the order that you want (something like =IF(A2="P1",MATCH(B2,{"C1","C3","C2"},0),1)), although that could get out of hand if you have lots of different types.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    A kludgy workaround might be to (assuming the boss just wants to read the reports)

    1. Have a PT do the heavy lifting the way most items are wanted, and have a macro to ...

    2. Copy the PT to new sheet as values

    3. Re-arrange just the non-standard order lines


    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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