簡體   English   中英

Excel,if函數,ifs,

[英]Excel , if function, ifs,

I assume x is the number I'm going to analyze and "y" is as "male" or "female" and "z" is as age group.

x是一個數字,其結果將是“體重不足”,“健康”或“超重”。 但是實際上是BPI的x對於男性和女性而言並不相同。 例如,如果x = 21然后取決於性別和年齡,則將其分類為“體重不足”,“健康”或“超重”。

 Function BAI(x As Integer, y As String, z As Integer) As String


 If x < 21 And y = "female" And 20 <= z <= 39 Then
    BAI = "UNDERWEIGHT"

 Elseif 22 <= x <= 33 And y = "Female" And 20 <= z <= 39 Then
    BAI = "Healthy"

ElseIf 34 <= x <= 38 And y = "Female" And 20 <= z <= 39 Then
    BAI = "overweight"

ElseIf x >= 39 And y = "Female" And 20 <= z <= 39 Then
    BAI = "OBESE"

ElseIf x <= 23 And y = "female" And 40 <= z <= 59 Then
    BAI = "UNDERWEIGHT"

ElseIf 24 <= x <= 35 And y = "female" And 40 <= z <= 59 Then
    BAI = "Healthy"

ElseIf 36 <= x <= 41 And y = "female" And 40 <= z <= 59 Then
    BAI = "Overweight"

ElseIf x >= 42 And y = "female" And 40 <= z <= 59 Then
    BAI = "OBESE"

ElseIf x <= 25 And y = "female" And 60 <= z <= 79 Then
    BAI = "UNDERWEIGHT"

ElseIf 26 <= x <= 38 And y = "female" And 60 <= z <= 79 Then
    BAI = "Healthy"

ElseIf 39 <= x <= 43 And y = "female" And 60 <= z <= 79 Then
    BAI = "Overweight"

ElseIf x >= 44 And y = "female" And 60 <= z <= 79 Then
    BAI = "obese"

ElseIf x <= 8 And y = "male" And 20 <= z <= 39 Then
    BAI = "Underweight"

ElseIf 9 <= x <= 21 And y = "male" And 20 <= z <= 39 Then
    BAI = "Healthy"

ElseIf 22 <= x <= 26 And y = "male" And 20 <= z <= 39 Then
    BAI = "overweight"

ElseIf x >= 27 And y = "male" And 20 <= z <= 39 Then
    BAI = "OBESE"

ElseIf x <= 11 And y = "male" And 40 <= z <= 59 Then
    BAI = "UNDERWEIGHT"

ElseIf 12 <= x <= 23 And y = "male" And 40 <= z <= 59 Then
    BAI = "Healthy"

ElseIf 24 <= x <= 28 And y = "male" And 40 <= z <= 59 Then
    BAI = "Overweight"

ElseIf x >= 29 And y = "male" And 40 <= z <= 59 Then
    BAI = "OBESE"

ElseIf x <= 13 And y = "male" And 60 <= z <= 79 Then
    BAI = "UNDERWEIGHT"

ElseIf 14 <= x <= 25 And y = "male" And 60 <= z <= 79 Then
    BAI = "Healthy"

ElseIf 26 <= x <= 30 And y = "male" And 60 <= z <= 79 Then
    BAI = "Overweight"

 End If

 End Function

您可以使用IF工作簿功能獲得所需的結果。 要在單個IF條件中獲得多個條件,請使用AND()和OR()函數。 要創建if-elseif類型邏輯,請將添加的IF()函數嵌套在適當的部分內。 舉個例子

=IF(OR(AND(A1="Male", A2>20),AND(A1="Female",A2>30)), IF(A3>200,"overweight","healthy"),"otherstuff")

這應該使您開始正確的道路。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM