Google Sheets Sort Column By Element Frequency

[Solved] Google Sheets Sort Column By Element Frequency | Excel - Code Explorer | yomemimo.com
Question : google sheets sort column by element frequency

Answered by : charlesalexandre-roy

# Basic syntax:
=SORT(A:A, COUNTIF(A:A, A:A), 0)
# Where:
#	- this will sort column A by the number of occurrences of each item
#	in column A
#	- COUNTIF($A:A, $A:A) only counts the occurrences of A1 in column A.
#	This is because COUNTIF is not an array formula. However, by
#	wrapping it inside the SORT function, that makes it behave as an
#	array formula, which causes it to return the count of each cell
#	in column A in column A
#	- SORT(A:A, ..., 0) sorts column A in descending order based on the
#	counts
# Note:
#	- if you want the unique occurrences of each item sorted by
#	frequency, wrap the sort function with UNIQUE()
#	- normally the second argument to SORT is the column number to sort
#	by, but it seems like if you provide an array of numbers of the
#	same length as the range, it uses those numbers first when
#	sorting, followed by any additional columns you specify
#	- the article this is based on uses IF(LEN(A:A), COUNTIF(...)). The
#	IF(LEN(A:A),,) part prevents the formula from including blank
#	cells, but isn't really necessary

Source : https://infoinspired.com/google-docs/spreadsheet/sort-by-number-of-occurrences-in-google-sheets/ | Last Update : Sun, 17 Jul 22

Answers related to google sheets sort column by element frequency

Code Explorer Popular Question For Excel