基于Client和Supply双条件的Excel跨表成本匹配函数应用求助
Hey there! Let's fix this lookup issue you're having. Your current IFS formula only checks a single row in your cost table instead of scanning all entries, and basic VLOOKUP setups often fail with multiple criteria since they rely on a single lookup column. Below are reusable, reliable solutions tailored to your needs:
1. XLOOKUP (Excel 365/2021+) – Most Concise
If you're using a modern Excel version, XLOOKUP is the simplest way to handle multi-condition lookups:
=XLOOKUP(1, (Table2[Client]=@Client)*(Table2[Supply]=@Supply), Table2[Cost], "No Match")
- How it works: The
(Table2[Client]=@Client)*(Table2[Supply]=@Supply)part creates an array of1s and0s, where1marks rows that match both your client and supply criteria.XLOOKUPfinds the first1and returns the corresponding cost fromTable2[Cost]. The final"No Match"is optional – it replaces errors if no matching entry exists.
2. INDEX + MATCH (All Excel Versions) – Maximum Compatibility
For older Excel versions or when you need broad compatibility, this classic combo is foolproof:
=INDEX(Table2[Cost], MATCH(1, (Table2[Client]=@Client)*(Table2[Supply]=@Supply), 0))
- Note for pre-365 Excel: You need to enter this as an array formula by pressing
Ctrl+Shift+Enterinstead of justEnter. - How it works:
MATCHlocates the row number where both conditions are true (the1in the array), thenINDEXpulls the cost value from that row in theTable2[Cost]column.
3. SUMPRODUCT (For Unique Client+Supply Combos)
If each Client+Supply pair only appears once in your cost table, SUMPRODUCT is another solid option:
=SUMPRODUCT((Table2[Client]=@Client)*(Table2[Supply]=@Supply)*Table2[Cost])
To handle cases where no match exists (instead of returning 0), wrap it in an IF statement:
=IF(SUMPRODUCT((Table2[Client]=@Client)*(Table2[Supply]=@Supply))=0, "No Match", SUMPRODUCT((Table2[Client]=@Client)*(Table2[Supply]=@Supply)*Table2[Cost]))
- How it works: It multiplies the condition arrays with the cost values – only rows that match both criteria contribute their cost to the sum, giving you the exact value you need.
Why Your Previous Attempts Failed
- Your
IFSformula only compares the current row ofTable2(using@Client/@Supply) instead of checking every row in the table. It can't scan all entries to find a match. - Basic
IF+VLOOKUPsetups usually fail here becauseVLOOKUPonly uses the first column of the lookup range for matching. You'd need to combine the Client and Supply columns into a single lookup key (e.g.,Table2[Client]&Table2[Supply]) to make it work, which is less clean than the solutions above.
内容的提问来源于stack exchange,提问作者Ranjar

