Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR EXCEL

google sheets sort column by element frequency

# 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 by infoinspired.com #
 
PREVIOUS NEXT
Tagged: #google #sheets #sort #column #element #frequency
ADD COMMENT
Topic
Name
6+4 =