In a new sheet, you can use these formulae to create a list of unique customer names and states.
You need to use two coordinating functions, in a new sheet enter the following function in A2
=IFERROR(INDEX(Sheet1!$A$2:$A$6, MATCH(0, COUNTIFS(Sheet2!$A$1:A1, Sheet1!$A$2:$A$6,Sheet2!$B$1:B1, Sheet1!$B$2:$B$6), 0)),"")
and the following function in B2
=IFERROR(INDEX(Sheet1!$B$2:$B$6, MATCH(0, COUNTIFS(Sheet2!$A$1:A1, Sheet1!$A$2:$A$6,Sheet2!$B$1:B1, Sheet1!$B$2:$B$6), 0)),"")
For this to work, the following needs to be true
- This needs to be placed in a second worksheet (rename
Sheet2
accordingly)
Sheet1!$A$2:$A$6
and Sheet1!$B$2:$B$6
should be modified (sheet name and range) to contain your full list of customer names and states respectively. If the list is too long, the last entry in your list of unique values will b 0
- The above formulae should be pasted in
Sheet2!A2
and Sheet2!B2
respectively
- These are array formulae. It should be entered into the designated cell and then submitted by hitting
ctrl+alt+enter
- After entering the initial formulae into
A2
and B2
as an array, copy and paste the formulae down Column A
and Column B
until unique names no longer appear.
(This answer is adopted from this question. There are a few variants as other answers)
Use an array function to return counties in ColumnC
. Paste the formula in C2
as an array (with updated references), and then copy it down the list.
=TEXTJOIN(", ",TRUE,IF((Sheet2!A2=Sheet1!$A$2:$A$6)*(Sheet2!B2=Sheet1!$B$2:$B$6),Sheet1!$C$2:$C$6,""))
Brief explination on how these functions work:
-Function 1:
- the
COUNTIFS
looks at your source data, and returns an array with 1
if it is already in the list, and a 0
if it is not.
MATCH
looks at the COUNTIFS
array, and identifies the first 0
INDEX
looks at your source data, and returns the row identified by MATCH
-Function2:
- The
IF
function creates two arrays of TRUE
or FALSE
based on whether the source data matches the unique customer and state of the row.
- Those arrays are multiplied, creating a new array that is
TRUE
only if both entries were TRUE
. (meaning both the customer and state matched)
- The
IF
statement returns the county if true, and if false, and empty cell ""
TEXTJOIN
filters out the empty cells (That is what the TRUE
is doing) and joins them together with a comma and a space (the delimiter).