I need to extract unique values from multiple ranges (only two ranges in my example, but more will be added) and display them in a single row, sorted in ascending order, without duplicates.
So far, I have used the following formula:
=SORT(UNIQUE(TOROW(VSTACK(B36:AF36, B67:AF67),1)),,1)
However, this formula is not sorting the values correctly and not removing duplicates as expected.
Example:
Given Data:
B36:AF36 → {1, 2, 3, 8, 15}
B67:AF67 → {4, 6, 15, 16}
Current Output (Incorrect)
{1, 2, 3, 8, 15, 4, 6, 15, 16}
(Concatenated but not sorted, and 15 appears twice)
Expected Output (Correct)
{1, 2, 3, 4, 6, 8, 15, 16}
(Sorted in ascending order with duplicates removed)
What formula should I use to ensure that the values from all ranges are correctly combined, sorted, and displayed uniquely in a single row?
Thanks in advance for any help!
I need to extract unique values from multiple ranges (only two ranges in my example, but more will be added) and display them in a single row, sorted in ascending order, without duplicates.
So far, I have used the following formula:
=SORT(UNIQUE(TOROW(VSTACK(B36:AF36, B67:AF67),1)),,1)
However, this formula is not sorting the values correctly and not removing duplicates as expected.
Example:
Given Data:
B36:AF36 → {1, 2, 3, 8, 15}
B67:AF67 → {4, 6, 15, 16}
Current Output (Incorrect)
{1, 2, 3, 8, 15, 4, 6, 15, 16}
(Concatenated but not sorted, and 15 appears twice)
Expected Output (Correct)
{1, 2, 3, 4, 6, 8, 15, 16}
(Sorted in ascending order with duplicates removed)
What formula should I use to ensure that the values from all ranges are correctly combined, sorted, and displayed uniquely in a single row?
Thanks in advance for any help!
Share Improve this question edited Feb 17 at 8:39 Lorenzo Castagno 6281 gold badge14 silver badges30 bronze badges asked Feb 10 at 22:46 cj69cj69 1131 gold badge1 silver badge4 bronze badges2 Answers
Reset to default 2You were almost there:
=SORT(UNIQUE(HSTACK(A1:E1,A2:E2),TRUE),,,TRUE)
Make sure the functions you are using work in the same direction - horizontal or vertical:
- Stack your arrays horizontally
- Take unique values, make sure to use 'TRUE' to return unique columns
- Sort provided array by columns.
Edit: if empty cells have to be filtered out:
=LET(
input, HSTACK(B36:AF36,B67:AF67),
SORT(UNIQUE(FILTER(input,HSTACK(input)<>"",""),TRUE),,,TRUE))
You may try the following formula-
=TOROW(SORT(UNIQUE(TOCOL(A1:E2,1))))
Input data:
1 | 2 | 3 | 8 | 15 |
4 | 6 | 15 | 16 |
Output:
1 | 2 | 3 | 4 | 6 | 8 | 15 | 16 |