# How to return the first item from a priority list that appears in another list

Check each priority item against the other list and return the first that is there: `=XLOOKUP(TRUE,COUNTIF(C2:C5,A2:A6)>0,A2:A6,"None available")`.

**Excel:** `=XLOOKUP(TRUE,COUNTIF(C2:C5,A2:A6)>0,A2:A6,"None available")` (Excel 2021, 2024 and Microsoft 365)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E |
| --- | --- | --- | --- | --- |
| Preferred supplier |  | In stock at |  | Order from |
| Acme Supply |  | Delmar Office |  |  |
| BrightCo |  | Corvex |  |  |
| Corvex |  | Evergreen Paper |  |  |
| Delmar Office |  | Foxhall Electric |  |  |
| Evergreen Paper |  |  |  |  |

Formula in E2: `=XLOOKUP(TRUE,COUNTIF(C2:C5,A2:A6)>0,A2:A6,"None available")`

Result: Corvex

## How it works

`COUNTIF(C2:C5,A2:A6)` counts each preferred supplier in the in-stock list, one count per supplier in priority order. Acme and BrightCo count 0, Corvex counts 1. XLOOKUP returns the first supplier with a count above 0.

## Other ways

- `=INDEX(A2:A6,MATCH(TRUE,INDEX(COUNTIF(C2:C5,A2:A6)>0,0),0))`: Every Excel version, without Ctrl+Shift+Enter.
- `=FILTER(A2:A6,COUNTIF(C2:C5,A2:A6))`: Lists every available supplier, still in priority order. (Corvex, Delmar Office and Evergreen Paper.)

## Common mistakes

- Search the priority list, not the in-stock list. Reversing them returns the first in-stock supplier in that list's order.
- Names must match exactly, apart from case.

## Questions

**How do I return the second choice too?**

Take the first two from the FILTER: `=TAKE(FILTER(A2:A6,COUNTIF(C2:C5,A2:A6)),2)`.

**Can the condition be a stock quantity instead?**

Yes: look up each supplier's stock and test it, for example `XLOOKUP(A2:A6,C2:C5,D2:D5,0)>=G1`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/first-priority-item-in-list
