2016-02-22 36 views
0

我試圖做一個多級別,如果其他查詢在Excel中,它將檢查多個變量,如果它落入其中一個類別那麼它會 - 一個百分比,如果它不屬於任何類別那麼它會說「N/A」如何在excel中查詢其他查詢?

的僞代碼將是這個樣子:

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") 

但我不知道如何做多個我f else在excel中的語句來捕獲所有可能的類別,或者如果有更好的方法。

+0

你可以嵌套IF函數來實現這一點,語法是這樣= IF(Condition,TRUE,IF(Condition,TRUE,IF(....))) –

回答

1

我會組各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))))) 
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 
+0

我試着做一個嵌套查詢。 (AND)(I4 <65,J4 <90000),800 *(1-0.27),「NA」,= IF(AND(I4> 64,I4 <69,J4> 90000,J4 <105001) NA「,= IF(AND(I4 <69,J4> 105001,J4 <140000),800 * 0.18,」NA「)))'這似乎沒有給我一個答案。 – kevincua

+0

你有太多的等號 - 應該只是一個公式開始。嵌套的「IF」總是前一個「IF」的「FALSE」條件,代替示例中的「NAs」。 –