+ Reply to Thread
Results 1 to 15 of 15

Sorting data within a cell by magnitude of percentages

  1. #1
    Registered User
    Join Date
    08-24-2020
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Sorting data within a cell by magnitude of percentages

    Hi,

    I have 18,000 cells with data like the following: Apple (10%); Banana (30%); Cherries (60%)

    I want to create an adjacent cell that will automatically rearrange it to look like this: Cherries (60%); Banana (30%); Apple (10%).

    Is there any way to do that?

    Thank you in an advance!

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: Sorting data within a cell by magnitude of percentages

    Please read the yellow banner at the top of this page on how to attach a file.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    08-24-2020
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: Sorting data within a cell by magnitude of percentages

    Sorry about that. Here's an example of what I have and what the goal is.
    Attached Files Attached Files

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: Sorting data within a cell by magnitude of percentages

    Using Power Query/Get and Transform found on the Data Tab

    Here is the Mcode to get your expected results.

    Please Login or Register  to view this content.
    Review PQ
    In the attached file
    Click on any cell in the new table
    On the Data Tab, click on Queries & Connections
    In the right window, double click to open Query
    Review PQ steps

    M-code basics:
    - "let" is the start of a query
    - "in" is the closing of a query
    - each transformation step sits in between those 2 lines
    - each step line is ended by a comma, except the last one
    - "Source" is always the first step (Source Data)
    - After "in" you have the last step referenced
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-24-2020
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: Sorting data within a cell by magnitude of percentages

    Thank you! Is there an easy way to concatenate the results so that I can get them all into one cell?

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sorting data within a cell by magnitude of percentages

    UDF

    Use in cell like
    =SortPerc(A2)

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-24-2020
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: Sorting data within a cell by magnitude of percentages

    Thank you! It works with my initial test data but then when I went to apply it to another cell, which has cities instead of one word items, it seemed to get thrown off.

    Here is my initial data:
    Boca Raton (4%); Boston (12%); Chicago (6%); Los Angeles (18%); New York (53%); Washington, DC (7%)

    Here is what came up after using SortPerc:
    Washington, DC (7%); Chicago (6%); New York (53%); Boca Raton (4%); Los Angeles (18%); Boston (12%)

    I feel like the answer is obvious but I am not the best with UDFs so I can't figure out what to tweak to adjust the formula. Can you please tell me what change to make? Thank you again for all your help!

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sorting data within a cell by magnitude of percentages

    If you upload all the possible pattern and the result that you want in a workbook, I can work from that.

  9. #9
    Registered User
    Join Date
    08-24-2020
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: Sorting data within a cell by magnitude of percentages

    Thanks! See attached.
    Attached Files Attached Files

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sorting data within a cell by magnitude of percentages

    Did you miss "Boca Raton (4%)" in your result?

    try change to
    Please Login or Register  to view this content.
    Edit; the line in bold.
    Last edited by jindon; 08-24-2020 at 09:57 PM.

  11. #11
    Registered User
    Join Date
    08-24-2020
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: Sorting data within a cell by magnitude of percentages

    Oh shoot I did; good catch. That one should have been last, sorry.

    I'm still getting the same results. I've attached the workbook again.
    Attached Files Attached Files

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sorting data within a cell by magnitude of percentages

    Because you are still using the 1st code I posted.

    You need to replace it with the one in my post #10

  13. #13
    Registered User
    Join Date
    08-24-2020
    Location
    New York
    MS-Off Ver
    2016
    Posts
    10

    Re: Sorting data within a cell by magnitude of percentages

    So weird I thought I kept copying over it but I guess I was not. It worked perfectly in a new book. Thank you so much!!

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,518

    Re: Sorting data within a cell by magnitude of percentages

    Yeah, it also happens to me sometime.

    You are welcome and thanks for the rep.

  15. #15
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: Sorting data within a cell by magnitude of percentages

    An alternative with Power Query
    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 11-28-2019, 09:23 AM
  2. help - chart with magnitude and direction?
    By miko.sims in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 09-28-2013, 10:21 AM
  3. Units of Fourier Analysis Magnitude
    By centrifuge in forum Excel General
    Replies: 6
    Last Post: 08-27-2013, 06:29 AM
  4. Sorting Percentages in decending order.
    By peterwithingtonuk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2010, 08:55 AM
  5. determining the relative magnitude of value in an array
    By luv2glyd in forum Excel General
    Replies: 2
    Last Post: 12-31-2009, 02:01 PM
  6. Sorting percentages in descending order
    By maacmaac in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-16-2008, 10:37 PM
  7. What is a relationship magnitude graphic chart
    By relationship magnitude graphic chart in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-23-2006, 01:45 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