+ Reply to Thread
Results 1 to 5 of 5

I want to sort according to frequency, largest to smallest.

Hybrid View

  1. #1
    Registered User
    Join Date
    07-10-2021
    Location
    GENEVA
    MS-Off Ver
    EXCEL FOR MAC MICROSOFT 365
    Posts
    83

    I want to sort according to frequency, largest to smallest.

    How can I get the words in column F to sort according to the frequency shown in column G?

    When I try conventional sorting methods, it tells me "You can't change part of an array".
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: I want to sort according to frequency, largest to smallest.

    I would use Power Query with the following Mcode

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Value"),
        #"Sorted Rows" = Table.Sort(#"Unpivoted Columns",{{"Value", Order.Ascending}}),
        #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Attribute"}),
        #"Grouped Rows" = Table.Group(#"Removed Columns", {"Value"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
        #"Sorted Rows1" = Table.Sort(#"Grouped Rows",{{"Count", Order.Descending}, {"Value", Order.Ascending}})
    in
        #"Sorted Rows1"
    Your formula produces a comma after each unique item and therefore cannot be matched to the info in Columns A:E as they don't have the trailing comma

    Excel 2016 (Windows) 64 bit
    I
    J
    1
    Value Count
    2
    Advancement
    2
    3
    Progress
    2
    4
    Accounting
    1
    5
    Accounting-manipulation
    1
    6
    Address
    1
    7
    Administration
    1
    8
    Betterment
    1
    9
    Blockchain
    1
    10
    Cryptography
    1
    11
    Development
    1
    12
    Digital
    1
    13
    Distributed
    1
    14
    Encryption
    1
    15
    Enhancement
    1
    16
    Expansion
    1
    17
    Financial-manipulation
    1
    18
    Fraud
    1
    19
    Growth
    1
    20
    Improvement
    1
    21
    Insider-trading
    1
    22
    Leadership
    1
    23
    Ledger
    1
    24
    Management
    1
    25
    Organization
    1
    26
    Public-Key
    1
    27
    Securities-fraud
    1
    28
    Security
    1
    29
    Team
    1
    30
    accountability
    1
    31
    clarity
    1
    32
    disclosure
    1
    33
    openness
    1
    34
    transparency
    1
    Sheet: Sheet1
    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
    07-10-2021
    Location
    GENEVA
    MS-Off Ver
    EXCEL FOR MAC MICROSOFT 365
    Posts
    83

    Re: I want to sort according to frequency, largest to smallest.

    Hi @alansidman, thanks for your quick reply.

    1) I have been trying for a while to figure out how to make power query work for me with your code, but it looks like I don't know what I am doing (I never used Power Query before). I assumed I was supposed to click on Get Data (Power Query), click "Home" and enter your code in Cell A1 of Query (01). I guess that is wrong, as I can not find any button to execute the code. Very sadly I have had to give up on trying your solution for the time being. But thanks so much for trying to help.

    2) You said: "Your formula produces a comma after each unique item and therefore cannot be matched to the info in Columns A:E as they don't have the trailing comma". You are right. I have managed to remove the commas by inserting the "substitute" function in cell F2 as follows:
    Old Formula =SORT(UNIQUE(TRANSPOSE(TEXTSPLIT(ARRAYTOTEXT(A2:E8)," "))))
    new Formula =SORT(UNIQUE(SUBSTITUTE(TRANSPOSE(TEXTSPLIT(ARRAYTOTEXT(A2:E8)," ")),",","")))

    An amended spreadsheet is attached
    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 insider Version 2505 Win 11
    Posts
    24,754

    Re: I want to sort according to frequency, largest to smallest.

    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,745

    Re: I want to sort according to frequency, largest to smallest.

    I am not familiar with Mac or if the TOCOL function is available in Office 365 for Mac. If it is you may find this a simpler way to get the sorted unique values. See this in column H of the attached.
    Formula: copy to clipboard
    =SORT(UNIQUE(TOCOL($A$2:$E$8,TRUE,)),,1,FALSE)


    I have not found a simple formula way of getting the sorted list by frequency. Someone else may be able to help with that. The best I could come up with was this beast. Entered into F2 and copy down.
    Formula: copy to clipboard
    =INDEX(SORT(UNIQUE(TOCOL($A$2:$E$8,TRUE,)),,1,FALSE),MATCH(LARGE(COUNTIF($A$2:$E$8,SORT(UNIQUE(TOCOL($A$2:$E$8,TRUE,)),,1,FALSE))-(SEQUENCE(SUMPRODUCT(1/COUNTIF($A$2:$E$8,$A$2:$E$8)),,2)/10^7),ROWS(F$2:F2)),COUNTIF($A$2:$E$8,SORT(UNIQUE(TOCOL($A$2:$E$8,TRUE,)),,1,FALSE))-(SEQUENCE(SUMPRODUCT(1/COUNTIF($A$2:$E$8,$A$2:$E$8)),,2)/10^7),0))


    About all I can say for that is that it works although it could be made simpler with 1 or more helper columns.
    Last edited by FlameRetired; 03-26-2023 at 07:26 PM. Reason: Corrected mistake in formula.
    Dave

+ 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] Get the most occurrences from an area and sort from largest to smallest
    By choletseng in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 03-12-2022, 11:21 AM
  2. [SOLVED] Sort Largest to Smallest, Left to Right With Statement
    By safari20WDG in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-16-2016, 02:06 PM
  3. Replies: 1
    Last Post: 04-16-2015, 06:29 PM
  4. How Sort by Largest to Smallest Column by Formula
    By termal in forum Excel General
    Replies: 10
    Last Post: 01-08-2014, 01:17 PM
  5. Sort largest to smallest - VBA
    By Ricardo Mass in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2013, 09:05 AM
  6. Sort Largest to smallest automatically
    By jmwilson in forum Excel General
    Replies: 6
    Last Post: 05-06-2012, 07:05 PM
  7. Excel 2007 : sort smallest number to largest
    By ravihotwok in forum Excel General
    Replies: 1
    Last Post: 12-06-2011, 11:35 AM

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