我使用Harris Benedict Equation来计算人们的TDEE。我使用Google表格为此创建了一种表单,但Google表格很难处理。我收到公式解析错误。格式化非常抱歉。
我知道我在某处做了一个小逗号或括号错误,但我不知道在哪里。
该代码应该询问人们是否更喜欢公制/英制,男/女,身高,体重,活动水平和年龄。
以下是Google表格if statements的工作原理。它几乎是 -
IF(A2 =" foo"," A2是foo")
语法是
IF(logical_expression,value_if_true,value_if_false)
=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,
“ “))))))
)
答案 0 :(得分:2)
你有IF(Lightly Active (1-3 days of exercise/week)”
之类的东西显然无法发挥作用。这种IF的嵌套不应该首先存在,它是拼写错误的雷区。请改用hlookup
或vlookup
。 vlookup
替换五个嵌套IF的示例:
=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,表格!A6:B11等:
=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!错误(虽然后者提供更多信息)。