首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用多个嵌套的IF语句调试适应度计算器

使用多个嵌套的IF语句调试适应度计算器
EN

Stack Overflow用户
提问于 2016-07-02 09:34:40
回答 1查看 40关注 0票数 0

我正在使用哈里斯本尼迪克特方程来计算人们的TDEE。我正在使用Google来创建一种表单,但是使用Google有点困难。我得到一个公式解析错误。格式化是很糟糕的,很抱歉。

我知道我在某个地方犯了一个小小的逗号或括号错误,但我不知道在哪里。

该守则旨在问人们是否更喜欢公制/英制、男性/女性、身高、体重、活动水平和年龄。

这里是Google如何做if语句的。基本上是:

代码语言:javascript
复制
IF(A2 = "foo","A2 is foo")

语法是:

如果(logical_expression,value_if_true,value_if_false)

代码语言:javascript
复制
=IF (D9=”Imperial”,
    IF(D10=”Male”,
            IF(D16=”Sedentary (no exercise)”,
                    66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.2,

                    IF(D16=”Lightly Active (1-3 days of exercise/week)”,
                            66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.375,

                            IF(D16=”Moderately Active (3-5 days of exercise/week)”,
                                    66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.55,

                                    IF(D16=”Very Active(6-7 days of exercise/week)”,

                                            66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.725,
                                            IF(D16=”Extremely Active(exercise twice a day)”,

                                                    66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.9,
                                            “ “)))))


            IF(D16=”Sedentary (no exercise)”,
                    655.1 + ( 4.35 x D14 ) + ( 4.7 x (D13x12+G13) ) - ( 4.7 x D12 ) x1.2,

                            IF(Lightly Active (1-3 days of exercise/week)”,
                                    655.1 + ( 4.35 x D14 ) + ( 4.7 x (D13x12+G13) ) - ( 4.7 x D12 ) x1.375,

                                    IF(Moderately Active (3-5 days of exercise/week)”,
                                            655.1 + ( 4.35 x D14 ) + ( 4.7 x (D13x12+G13) ) - ( 4.7 x D12 ) x1.55,

                                            IF(D16=”Very Active(6-7 days of exercise/week)”,
                                                    655.1 + ( 4.35 x D14 ) + ( 4.7 x (D13x12+G13) ) - ( 4.7 x D12 ) x1.725,

                                                    IF(D16=”Extremely Active(exercise twice a day)”,
                                                            655.1 + ( 4.35 x D14 ) + ( 4.7 x (D13x12+G13) ) - ( 4.7 x D12 ) x1.9,
                                                    “ “))))))


    IF(D10=”Male”,
            IF(D16=”Sedentary (no exercise)”,
                    66.5 + ( 13.75 x D14 ) + ( 5.003 x D13 ) – ( 6.755 x D12 )x1.2,


                    IF(Lightly Active (1-3 days of exercise/week)”,
                            66.5 + ( 13.75 x D14 ) + ( 5.003 x D13 ) – ( 6.755 x D12 )x1.375,


                            IF(Moderately Active (3-5 days of exercise/week)”,
                                    66.5 + ( 13.75 x D14 ) + ( 5.003 x D13 ) – ( 6.755 x D12 )x1.55,


                                    IF(D16=”Very Active(6-7 days of exercise/week)”
                                            66.5 + ( 13.75 x D14 ) + ( 5.003 x D13 ) – ( 6.755 x D12 )x1.725,


                                            IF(D16=”Extremely Active(exercise twice a day)”,

                                                    66.5 + ( 13.75 x D14 ) + ( 5.003 x D13 ) – ( 6.755 x D12 )x1.9,

                                            “ “)))))



            IF(D16=”Sedentary (no exercise)”,
                    655.1 + ( 9.563 x D14 ) + ( 1.850 x D13 ) – ( 4.676 x D12 ) x1.2,


                    IF(Lightly Active (1-3 days of exercise/week)”,
                            655.1 + ( 9.563 x D14 ) + ( 1.850 x D13 ) – ( 4.676 x D12 ) x1.375,


                            IF(Moderately Active (3-5 days of exercise/week)”,
                                    655.1 + ( 9.563 x D14 ) + ( 1.850 x D13 ) – ( 4.676 x D12 ) x1.55,


                                    IF(D16=”Very Active(6-7 days of exercise/week)”,

                                            655.1 + ( 9.563 x D14 ) + ( 1.850 x D13 ) – ( 4.676 x D12 ) x1.725,


                                            IF(D16=”Extremely Active(exercise twice a day)”,

                                                    655.1 + ( 9.563 x D14 ) + ( 1.850 x D13 ) – ( 4.676 x D12 ) x1.9,

                                            “ “))))))

    )
EN

回答 1

Stack Overflow用户

发布于 2016-07-02 15:01:23

IF(Lightly Active (1-3 days of exercise/week)”这样的东西显然是行不通的。这种嵌套的IFs不应该在第一,它是一个雷区的打字。使用hlookupvlookup代替。vlookup替换五个嵌套IFs的示例:

代码语言:javascript
复制
=if(D9=”Imperial”,
  if(D10=”Male”,
    vlookup(D16, {
      ”Sedentary (no exercise)”,
        66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.2;   
      ”Lightly Active (1-3 days of exercise/week)”,
        66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.375;
      ”Moderately Active (3-5 days of exercise/week)”,
        66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.55;
      ”Very Active(6-7 days of exercise/week)”,
        66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.725;
      ”Extremely Active(exercise twice a day)”,
        66 + ( 6.2 x D14 ) + ( 12.7 x (D13x12+G13) ) – ( 6.76 x D12 )x1.9,
       }, 2, false)
    ....

请注意,您可以在这里放置15而不是5个选项,并且不需要新的括号。

根据数据的结构方式,您可以将这个参考表放在工作表的其他地方,例如表!A1:b5、Table!A6:B11等等:

代码语言:javascript
复制
=if(D9=”Imperial”,
   if(D10=”Male”,
     vlookup(D16, Table!A1:B5, 2, false),
     vlookup(D16, Table!A6:B11, 2, false)
     ),
   if(D10=”Male”,
     vlookup(D16, Table!A12:B16, 2, false),
     vlookup(D16, Table!A17:B21, 2, false)
     )
   )

可以将每个vlookup封装在iferror中,这样当输入数据不是预期的类型时,就可以得到空白输出,而不是#N/A!错误(尽管后者提供了更多信息)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38158649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档