Return Excel Values by Matching Names and a Column Q Condition
Question details
Return a corresponding value for each name based on whether its matching row has 1 in column Q.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Names in column B must be matched against lookup tables, with the result taken from column P when the matching column Q value is 1, or from column L otherwise.
- Observed behavior
- Each name should receive its corresponding lookup value, such as 50, or remain blank if the relevant lookup finds no match.
Check that the names to look up are in B6:B15, the first lookup table uses O5:Q8, and the fallback table uses K5:L8. Make sure the condition in column Q is the numeric value 1, and adjust the ranges if your data is elsewhere.
Use XLOOKUP to return a value based on the column Q condition
Use this formula in an Excel version that supports XLOOKUP to select a value from column P or L for each name.
Select C6 and enter =IF(B6="","",IF(XLOOKUP(B6,$O$5:$O$8,$Q$5:$Q$8,"")=1,XLOOKUP(B6,$O$5:$O$8,$P$5:$P$8),XLOOKUP(B6,$K$5:$K$8,$L$5:$L$8,""))).
Select C6 and drag its fill handle down through C15 to apply the lookup to each name in column B.
Compare the results in column C with the matching rows in O5:Q8 and K5:L8. If Q is 1, the formula returns P; otherwise, it looks for the name in K and returns L.

Use INDEX and MATCH when XLOOKUP is unavailable
Use this alternative in Excel versions that do not support XLOOKUP.
Match names and return conditional values in WPS Spreadsheets
Open your workbook in WPS Spreadsheets and use INDEX and MATCH to check column Q and return the corresponding value from column P or L.
- 1. Open the workbook: Open WPS Spreadsheets and use Open to select your Excel workbook.
- 2. Enter the lookup formula: Select C6 and enter =IF(B6="","",IF(IFERROR(INDEX($Q$5:$Q$8,MATCH(B6,$O$5:$O$8,0)),"")=1,IFERROR(INDEX($P$5:$P$8,MATCH(B6,$O$5:$O$8,0)),""),IFERROR(INDEX($L$5:$L$8,MATCH(B6,$K$5:$K$8,0)),""))).
- 3. Apply it to the other names: Drag the fill handle from C6 through C15 and verify the results against your lookup tables.
- 4. Save the workbook: Choose Menu > Save As and select the Excel XLSX format if you need to share the workbook with Excel users.

Frequently Asked Questions
What happens if a name is missing from column O?
The formula checks the fallback table in K5:L8. If the name is found in column K, it returns the corresponding value from column L; otherwise, it returns a blank.
Why does the formula return a value from column L instead of P?
The formula uses column P only when the first matching name in O5:O8 has the numeric value 1 in column Q. Otherwise, it looks up the name in column K and returns the value from L.
What if the same name appears more than once?
XLOOKUP and MATCH use the first matching name in their respective lookup ranges. Review O5:O8 and K5:K8 for duplicates if the result is unexpected.
Can I use the formula without XLOOKUP?
Yes. Enter the INDEX and MATCH alternative in C6 and fill it down. It performs the same conditional lookup without XLOOKUP.




