+ Reply to Thread
Results 1 to 4 of 4

Sorting Hierarchical Excel Table Keeping Certain Rows/Groups Intact

  1. #1
    Registered User
    Join Date
    11-04-2019
    Location
    Marsaskala, Malta
    MS-Off Ver
    Office 365
    Posts
    2

    Sorting Hierarchical Excel Table Keeping Certain Rows/Groups Intact

    Hi!

    I have an an excel sheet containing data in a sort of 'hierarchical' form.
    Basically this is Energy consumption data for various zones; these are first split into different clusters, which are further split into Zones, some of which are also split into Sub-Zones.

    For Example:
    Cluster A---Average Value for Cluster A :10
    ---Zone A1 :9
    ---Zone A2 :10.5
    ------->Sub-Zone A2.1 :7
    ------->Sub-Zone A2.2 :12
    ---Zone A3 :9.5

    Cluster B---Average Value for Cluster B :14
    ---Zone B1 :16
    ---Zone B2 :11.5
    ------->Sub-Zone B2.1 :10
    ------->Sub-Zone B2.2 :14
    ---Zone B3 :15

    This is a fairly large list containing 100-200 entries. My goal here is to sort this data in a descending order while keeping the hierarchical order, in order to see areas with highest consumption.
    So the Cluster with the highest average would be on top, with all the zones contained in the cluster being then sorted similarly in a descending order, and any Sub-zones within the zones being also sorted in a descending order (while still being listed under their parent zone, which is sorted and listed under the parent cluster).

    Basically I first want to sort the Clusters in descending order of consumption as if they were single entries, then within each sorted Cluster 'group' I essentially want to run a second sorting, this time sorting the Zones in descending order (while keeping the parent clusters sorted as in the initial sorting), and similarly a third sorting for any sub-zones.

    The given example would thus be as follows:

    Cluster B---Average Value for Cluster B :14
    ---Zone B1 :16
    ---Zone B3 :15
    ---Zone B2 :11.5
    ------->Sub-Zone B2.2 :14
    ------->Sub-Zone B2.1 :10


    Cluster A---Average Value for Cluster A :10
    ---Zone A2 :10.5
    ------->Sub-Zone A2.2 :12
    ------->Sub-Zone A2.1 :7
    ---Zone A3 :9.5
    ---Zone A1 :9

    Is there any way that this can be achieved? I have been trying to find a good way to do this for the past hour, but I can't really come up with anything.
    I might have to experiment a bit with a custom VBA macro, but I've been avoiding that as I only know the very basics heh.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Sorting Hierarchical Excel Table Keeping Certain Rows/Groups Intact

    Welcome to the forum.

    Will you please attach a small sample Excel workbook? We are not able to work with or manipulate a picture of one and nobody wants to have to recreate your data from scratch.

    Instructions (Please Read Carefully):

    1. Make sure that your sample data are REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired results are also shown (mock up the results manually).

    3. Make sure that all confidential data is removed or replaced with dummy data first (e.g. names, addresses, E-mails, etc.).

    4. Try to avoid using merged cells as they cause lots of problems.

    Unfortunately the attachment icon doesn't work at the moment (it hasn't worked for years, and despite our repeatedly asking the technical team who own the forum to fix it, they can't be bothered to do so), so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

    Please pay particular attention to point 2 (above): without an idea of your intended outcomes, it is often very difficult to offer appropriate advice.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    11-04-2019
    Location
    Marsaskala, Malta
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Sorting Hierarchical Excel Table Keeping Certain Rows/Groups Intact

    This post should include an example
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,531

    Re: Sorting Hierarchical Excel Table Keeping Certain Rows/Groups Intact

    This proposal makes some modifications to the original data.
    In column A the blanks are filled. This could be accomplished using the information in the linked tutorial.
    In column B the blanks corresponding to sub zones are filled. (manually)
    Columns E:G separated the values found in column D by category. (various formulas)
    Columns H:J rank the values in columns E:G (various formulas)
    Column K applies hierarchical numbering to the rankings using: =IF(ISNUMBER(H2),H2,IF(ISNUMBER(I2),SUM(INT(K1),I2/10),SUM(ROUND(K1,1),J2/100)))
    Column L sorts the values in column K using: =AGGREGATE(15,6,K$2:K$19,ROWS(A$1:A1))
    Columns M:O display the sorted categories using formulas similar to: =IF(LEN(MOD(L2,1))=1,INDEX(A$2:A$19,MATCH(L2,K$2:K$19,0)),"")
    Column P displays the sorted values (from column D) using: =INDEX(D$2:D$19,MATCH(L2,K$2:K$19,0))
    Let us know if you have any questions.
    Attached Files Attached Files
    Last edited by JeteMc; 11-06-2019 at 09:28 AM.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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 but keeping groups of rows together
    By PhillipSh in forum Excel General
    Replies: 6
    Last Post: 09-07-2019, 01:02 PM
  2. update few columns in rows from another row keeping others intact
    By malathi1972 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2018, 10:04 AM
  3. [SOLVED] Macro To copy information in a table (keeping format and nested table intact)
    By meabrams in forum Word Programming / VBA / Macros
    Replies: 6
    Last Post: 03-29-2017, 03:20 AM
  4. [SOLVED] Sort table while keeping multiple columns intact
    By Lucelline in forum Excel General
    Replies: 3
    Last Post: 05-03-2016, 03:49 AM
  5. Sorting vertical while keeping everything intact horizontally?
    By CJJ1984 in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-20-2012, 10:04 PM
  6. Sorting & keeping data intact?
    By elfiky in forum Excel General
    Replies: 1
    Last Post: 03-24-2009, 04:38 PM
  7. keeping rows intact during sort
    By Jim in forum Excel General
    Replies: 2
    Last Post: 11-24-2005, 10:10 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