Excel / SQL lookup · Original fictional case · Free files and answers
XLOOKUP practice: reject ambiguous customer keys
A CRM export contains repeated master rows and conflicting account owners. Supply an owner for each opportunity only when the master provides a single distinct owner.
Suggested time: 15–25 minutes. All records, companies, rates and work policies are invented for this exercise.
Your output contract
- Identical owner rows are harmless repeats; distinct owner names for the same customer are a conflict.
- Use REVIEW_DUPLICATE for conflicting keys and REVIEW_MISSING for absent keys. Never silently take the first conflicting owner.
- Output opportunity_id, owner_status in opportunity_id order.
Required columns: opportunity_id, owner_status. Row order is part of the contract. Empty output CSV fields represent NULL; zero remains 0.
Original source tables
opportunities
4 source rows · Download opportunities CSV
| opportunity_id TEXT | customer_id TEXT |
|---|---|
| P01 | K1 |
| P02 | K2 |
| P03 | K3 |
| P04 | K8 |
owners
5 source rows · Download owners CSV
| customer_id TEXT | owner TEXT |
|---|---|
| K1 | Mina |
| K1 | Mina |
| K2 | Owen |
| K2 | Rae |
| K3 | Sol |
Plan the transformation
- Build a distinct customer/owner table before checking key counts.
- Flag K2 as a conflict; deduplicate K1 to one trusted mapping.
- Join or look up the trusted mapping and keep all four opportunities with explicit review labels.
Watch for this mistake
A plain XLOOKUP returns the first match. Its successful result does not establish that the lookup key is unique.
Work in Excel
On a separate Trusted sheet create K1/Mina, K2/REVIEW_DUPLICATE and K3/Sol after inspecting distinct owners. Use =XLOOKUP(B2,Trusted!$A$2:$A$4,Trusted!$B$2:$B$4,"REVIEW_MISSING",0). Copy opportunity_id and the result into the two-column deliverable.
Use a version that supports XLOOKUP, such as Microsoft 365, Excel 2021 or Excel 2024. XLOOKUP is unavailable in Excel 2016 and 2019. The browser editor below executes SQLite; check an Excel result by uploading your final CSV.
Microsoft XLOOKUP syntax and compatibility
Run and check your SQLite result
The database runs locally in a worker. Use one SELECT or WITH query. Your query is saved on this device when storage is available. Download your SQL before clearing browser data.
Or work in Excel or another spreadsheet, then upload the final CSV with exactly the required columns.
Worked SQL and complete expected output
K1 has two raw rows but one distinct owner. K2 has two distinct owners; P04 has no mapping.
WITH u AS (SELECT DISTINCT customer_id,owner FROM owners), m AS (SELECT customer_id,COUNT(*) n,MIN(owner) owner FROM u GROUP BY customer_id) SELECT p.opportunity_id,CASE WHEN m.n IS NULL THEN 'REVIEW_MISSING' WHEN m.n>1 THEN 'REVIEW_DUPLICATE' ELSE m.owner END owner_status FROM opportunities p LEFT JOIN m USING(customer_id) ORDER BY p.opportunity_id;
| opportunity_id | owner_status |
|---|---|
| P01 | Mina |
| P02 | REVIEW_DUPLICATE |
| P03 | Sol |
| P04 | REVIEW_MISSING |
Download reference SQL · Download complete expected CSV · Download an empty answer CSV · Download SQLite setup
What to pass to a colleague
Keep the checked output and SQL or spreadsheet result. Explain the exception policy, the cross-check above and any held records. The checker confirms this fixed case’s output; it does not evaluate arbitrary private business data.
SQLite SELECT, joins and aggregation reference · Continue with the larger workplace projects