Nested IF statement returning false

三世轮回 提交于 2019-12-24 03:37:38

问题


I have a nested if statement is returning "False" rather than the expected outcome.

Scenario

Table "High VoltageCables" has data in it that default to numeric but may contain characters: kVa

Table "Master" checks "High VoltageCables" data as blank or not blank, and returns "Failed Check 1","Passed Check 1". This works fine.

Table "Meta" then checks the results of "Master" and then tests "High VoltageCables" data for length between 1 and 6, regardless of whether record is numeric or string.

Formula

=IF(MASTER!H2="Passed Check 1",IF(LEN('High VoltageCables'!O2)>=1,IF(LEN('High VoltageCables'!O2<6),"Passed Check 2","Failed Check 2")))

This is partially succesful, as it returns "Passed Check 2" for the following sample data in the source table "High VoltageCables".

1 numeric, or

1kVa str, or

50000 numeric

However if a field in "High VoltageCables"is blank, the formula returns "FALSE" rather than "Failed Check 1"

I inherited this task, (and would have preferred to do the whole thing in Access using relatively simple queries) - and unfortunately I am new to nested If statements, so I am probably missing something basic...

NB the data in High VoltageCables must default to numeric for a further check to work.


回答1:


The first and second IF's seem to be missing the else part. They should be added at the end between the ))) like ), else ), else ) Every IF statement consists of IF( condition, truepart, falsepart) if you have two nested ifs it will be something like IF( condition, IF( condition2, truepart2, falsepart2), falsepart) Hope that makes it a little clearer




回答2:


You do have an unaccounted for FALSE in the middle IF. Try bring the latter two conditions together.

=IF(Master!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"))

It's still a bit unclear on what to show or not show if Master!H2 does not equal "Passed Check 1".




回答3:


I failed to construct the formula with a concluding "else" - "Failed Check 1"

Using jeeped's and Tom's suggestion and adding the final "else" part I have solved the problem:

=IF(MASTER!H2="Passed Check 1",IF(OR(LEN('High VoltageCables'!O2)={1,2,3,4,5}),"Passed Check 2","Failed Check 2"),"Failed Check 1")


来源:https://stackoverflow.com/questions/32650572/nested-if-statement-returning-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!