如果在 excel 中进行多级查询,如何进行多级查询



我正在尝试在 excel 中进行多级查询,它会检查多个变量,如果它属于其中一个类别,那么它会 - 一个百分比,如果它不属于任何类别,那么它会说"N/A"

伪代码如下所示:

If $income <90,000 and $age is <65 then - 27.82%,
else if $income range(90,000 - 105,000)  and $age <65 then $premium - 18.55%,
else if $income range(105,001 - 140,000)  and $age <65 then $premium - 9.27%,
else if $income >140,000 and $age <65 then - 0%,
else if $income <90,000 and $age range(65-69) then $premium - 32.46%,
else if $income range(90,000 - 105,000) and $age range(65-69) then $premium - 23.18%,
else if $income range(105,001 - 140,000)  and $age range(65-69) then $premium - 13.91%,
else if $income >140,000 and $age range(65-69) then $premium - 0%,
else if $income <90,000 and $age <70 then - 37.09%,
else if $income range(90,000 - 105,000)  and $age <70 then $premium - 27.82%,
else if $income range(105,001 - 140,000)  and $age <70 then $premium - 18.55%,
else if $income >140,000 and $age <70 then $premium - 0%,
else "NA";

$income = cell j4
$age = cell i4
$premium = cell q4

我能够执行如下所示的单级查询:

=IF(AND(I5>64,I5<69,J5>90000,J5<105001),800*$Y$5,"NA")

但我不确定如何在 excel 中执行多个 if else 语句以捕获所有可能的类别,或者是否有更好的方法。

我会先将各种if语句分组到年龄范围内,然后对每个年龄组内的收入进行if语句。

像这样:

=IF(I4<65,
    IF(J4<90000,27.82,IF(J4<=105000,18.55,IF(J4<=140000,9.27,0))),
    IF(I4<=69,
        IF(J4<90000,32.46,IF(J4<=105000,23.18,IF(J4<=140000,13.91,0))),
        IF(J4<90000,37.09,IF(J4<=105000,27.82,IF(J4<=140000,18.55,0)))))

这是一个带有注释的版本(实际上不要将其粘贴到Excel中):

=IF(I4<65, // if the age is less than 65
    IF(J4<90000,27.82,IF(J4<=105000,18.55,IF(J4<=140000,9.27,0))),
    // else if the age is less than or equal to 69
    IF(I4<=69,
        IF(J4<90000,32.46,IF(J4<=105000,23.18,IF(J4<=140000,13.91,0))),
        // else (the age must be 70 or greater so need to specify this)
        IF(J4<90000,37.09,IF(J4<=105000,27.82,IF(J4<=140000,18.55,0)))))
嵌套的

IF 语句:

IF( condition1, value_if_true1, IF( condition2, value_if_true2, value_if_false2 ))

IF-ELSE 语句:

IF condition1 THEN
value_if_true1
ELSEIF condition2 THEN
value_if_true2
ELSE
value_if_false2
END IF

最新更新