Excel UNIQUE, FILTER, and SORT Complete Guide: Remove Duplicates, Filter, and Sort in 3 Minutes

Excel UNIQUE, FILTER, and SORT Complete Guide: Remove Duplicates, Filter, and Sort in 3 Minutes

With a dynamic-array-based UNIQUE, FILTER, and SORT combination, you can automatically create an analysis table without modifying the source data. Copy and paste the examples below to reproduce the same results.

Quick Fix: 3-Minute Pipeline

  1. Convert the source data to a table with Ctrl+T (Sales).
  2. Create a unique list with UNIQUE: =SORT(UNIQUE(Sales[Category]))
  3. Extract rows with criteria using FILTER: =FILTER(Sales,(Sales[Channel]="Online")*(Sales[Date]>=DATE(2025,8,26)))
  4. Sort by revenue in descending order with SORTBY: =SORTBY(FILTER(...), Sales[Revenue], -1)

Concepts: Function Roles and Combination Order

  • UNIQUE removes duplicates, FILTER extracts rows that meet criteria, and SORT/SORTBY sorts data (use SORTBY for multiple criteria).
  • List → UNIQUE → SORT / Extract rows → FILTER → SORTBY

Practical Example (Copy and Paste)

DateChannelCategoryItemQtyRevenue
2025-08-25OnlineTopsT001390000
2025-08-25StoreBottomsB014135000
2025-08-26OnlineTopsT002265000
2025-08-26OnlineShoesS1011120000
2025-08-27StoreShoesS1022240000
2025-08-28OnlineOuterO0101159000
2025-08-29OnlineTopsT0035165000
2025-08-30StoreOuterO0111199000
2025-08-30OnlineBottomsB021278000
2025-08-31OnlineShoesS2011140000

Unique Category List

=SORT(UNIQUE(Sales[Category]))

Online and Date Range Filter

=FILTER(Sales, (Sales[Channel]="Online")*(Sales[Date]>=DATE(2025,8,26)))

Sort Revenue in Descending Order

=SORTBY(FILTER(Sales,(Sales[Channel]="Online")*(Sales[Date]>=DATE(2025,8,26))), Sales[Revenue], -1)

Partial Match and Exclusion Term

=LET(k,"tops", ex,"T003", r,Sales, cond1,ISNUMBER(SEARCH(k,Sales[Category])), cond2,NOT(ISNUMBER(SEARCH(ex,Sales[Item]))), FILTER(r,cond1*cond2))

Category Totals

=LET(cats,UNIQUE(Sales[Category]), sums, MAP(cats, LAMBDA(c, SUM(FILTER(Sales[Revenue], Sales[Category]=c)))), HSTACK(cats, sums))

Top N Categories

=LET(cats,UNIQUE(Sales[Category]), sums, MAP(cats,LAMBDA(c,SUM(FILTER(Sales[Revenue],Sales[Category]=c)))), ranktbl, SORTBY(HSTACK(cats,sums), INDEX(HSTACK(cats,sums),,2), -1), TAKE(ranktbl,3))

Sort by Multiple Criteria

=SORTBY(Sales, Sales[Revenue], -1, Sales[Qty], 1)

Report with Only the Required Columns

=CHOOSECOLS(SORTBY(FILTER(Sales,Sales[Channel]="Online"), Sales[Revenue], -1), 1,3,4,6)

LAMBDA(TopNByRevenue)

=LAMBDA(tbl, n, LET(cats,UNIQUE(INDEX(tbl,,3)), sums, MAP(cats,LAMBDA(c,SUM(FILTER(INDEX(tbl,,6), INDEX(tbl,,3)=c)))), ranktbl, SORTBY(HSTACK(cats,sums), INDEX(HSTACK(cats,sums),,2), -1), TAKE(ranktbl, n)))

Alternatives, Notes, and Checklist

  • For large datasets and formal ETL, Power Query/Power Pivot is recommended.
  • Combine criteria with: AND = *, OR = +, NOT().
  • For nonbreaking spaces, use SUBSTITUTE(CHAR(160)," ") + TRIM.
  • If results conflict (#CALC!), clear the spill range.

Troubleshooting

IssueCauseSolution
#CALC! spill errorOutput range conflictMove the formula to an empty area
New rows are not includedRegular range referenceConvert the data to a table and use column-name references
Sort priority is incorrectUsing SORT with one criterionUse SORTBY with multiple criteria
Search results are missingSpaces or nonbreaking spacesUse TRIM/SUBSTITUTE

Conclusion

The UNIQUE, FILTER, and SORT pipeline alone can automatically refresh an analysis table while preserving the source data. The next article combines it with VSTACK and WRAPROWS to complete chart automation.

Leave a Reply

Your email address will not be published. Required fields are marked *