[英]How to use VLOOKUP with exceptions?
To assign the office responsible for a certain country I use a VLOOKUP function. In this way, Office China is responsible for Country China, Office Germany for Country Germany, etc.为了分配负责某个国家/地区的办公室,我使用 VLOOKUP function。这样,中国办公室负责中国,德国办公室负责德国等。
There are some cases, dependent on a license, that should be assigned to other Offices, not following the VLOOKUP function.有些情况下,根据许可证,应分配给其他局,而不是遵循 VLOOKUP function。
For example:例如:
There are a number of exceptions.有许多例外。 How do I build these exceptions into the VLOOKUP function?
如何将这些异常构建到 VLOOKUP function 中?
You can use the following in cell D2
:您可以在单元格
D2
中使用以下内容:
=IF(A2:A100="","",IFERROR(XLOOKUP(B2:B100,TB_Exceptions[License],
TB_Exceptions[Office]), IFERROR(XLOOKUP(C2:C100,
TB_CountryOffice[Country],TB_CountryOffice[Office]),
"CASE NOT FOUND")))
or using LET
function to facilitate maintenance of the formula:或者使用
LET
function 方便维护公式:
=LET(nameRng, A2:A100, licRng,B2:B100, countryRng, C2:C100,
IF(nameRng="","",IFERROR(XLOOKUP(licRng,TB_Exceptions[License],
TB_Exceptions[Office]),IFERROR(XLOOKUP(countryRng,
TB_CountryOffice[Country],TB_CountryOffice[Office]),
"CASE NOT FOUND")))
)
We are using a nested XLOOKUP
starting first with the most restricted search, ie the exceptions, and in case of #N/A
then it looks for the regular country lookup table.我们正在使用嵌套的
XLOOKUP
,首先从最受限制的搜索开始,即例外情况,如果出现#N/A
则它会查找常规国家/地区查找表。 We consider the CASE NOT FOUND
as a last resort in case some lookup value was not defined.如果未定义某些查找值,我们将
CASE NOT FOUND
视为最后的手段。
We are using Excel Tables to have dynamic ranges in the lookup tables.我们正在使用Excel 表在查找表中具有动态范围。 For the initial data set we don't use it, because for Excel Tables Spilled array formulas aren't supported, ie it returns
#SPILL!
对于初始数据集,我们不使用它,因为对于Excel 表,不支持溢出数组公式,即返回
#SPILL!
error.错误。
We define the data input ranges larger than the actual input data set, in case we want to include additional data.我们定义的数据输入范围大于实际输入数据集,以防我们想要包含额外的数据。 We add the initial condition:
IF(A2:A100="","",..)
to treat the blank lines of the input table.我们添加初始条件:
IF(A2:A100="","",..)
来处理输入表的空行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.