Nested IF statement returning false - excel

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.

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

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

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

Related

If(AND) combination produces "You've entered too many arguments for this function" error

hello everyone I'm here and needs help with excel
message from excel is
(you've entered too many arguments for this function)
and that my function.
=IF(AND(H2="A","B"),"group 1",IF(AND(N2H2="C","D"),"group 2",""))
please any one can help ?
The first condition to test within the IF statement "AND(H2="A","B")" will always return false - as this tests "Is H2 = "A" ? AND "Is '"B"'?
H2 cannot equal "A" and "B" simultaneously, and besides, even if you wanted to test that you'd have to use "AND(H2="A", H2="B").
Imagine someone asking you the Q "Is H2 = "A"?"
You could answer this if you knew what was in cell H2 (like Excel does) - and you could answer 'True' (yes) or 'False' (no).
But if you were asked is "B" as well? you would probably be quite puzzled - perhaps you would reply "Is "B" what as well"?
Excel would also be puzzled and in such circumstances the default response is 'False' (until proven otherwise!)
The 2nd AND statement is the wrong syntax - see here for some examples of how to use the AND statement.
This is probably why you are seeing the error you see - again:
If someone asked you "Is N2H2="C" and is "B" as well?
You wouldn't know which cell I was referring to (N2H2 does not exist in Excel)
Further, you wouldn't know what to say to "Is "B"?" (Is it a consonent? Is it capital? Is it the 2nd letter of the alphabet? Is it what?
Using this equation Excel will not return an error "too many arguments", it will return "invalid name error" (because there is no such thing as "N2H2" as far as Excel is concerned")
You need to use the following generic syntax for AND statements of this type:
AND(cell 1=some value1, cell 2= some value2) - not AND(cell1cell2=some value1, some value2)
i.e. this would be correct syntax:
=IF(AND(H2="A",N2="B"),"group 1",IF(AND(H2="D",N2="C"),"group 2",""))
(but it assumes you are trying to test cell N2 = B in the first AND statement because it's impossible for cell H2 to equal both A and B at the same time as I've said above)
As someone has pointed out in the comments - if you're testing whether H2 can be "A" OR "B" then simply use the OR statement - i.e. something like this:
=IF(OR(H2="A",H2="B"),"group 1",IF(AND(H2="D",N2="C"),"group 2",""))
https://support.microsoft.com/en-us/office/and-function-5f19b2e8-e1df-4408-897a-ce285a19e9d9

Cognos Report Studio: CASE and IF Statements

I'm very new in using Cognos report studio and trying to filter some of the values and replace them into others.
I currently have values that are coming out as blanks and want to replace them as string "Property Claims"
what i'm trying to use in my main query is
CASE WHEN [Portfolio] is null
then 'Property Claims'
ELSE [Portfolio]
which is giving me an error. Also have a different filter i want to put in to replace windscreen flags to a string value rather than a number. For example if the flag is 1 i want to place it as 'Windscreen Claims'.
if [Claim Windscreen Flag] = 1
then ('Windscreen')
Else [Claim Windscreen Flag]
None of this works with the same error....can someone give me a hand?
Your first CASE statement is missing the END. The error message should be pretty clear. But there is a simpler way to do that:
coalesce([Portfolio], 'Property Claims')
The second problem is similar: Your IF...THEN...ELSE statement is missing a bunch of parentheses. But after correcting that you may have problems with incompatible data types. You may need to cast the numbers to strings:
case
when [Claim Windscreen Flag] = 1 then ('Windscreen')
else cast([Claim Windscreen Flag], varchar(50))
end
In future, please include the error messages.
it might be syntax
IS NULL (instead of = null)
NULL is not blank. You might also want = ' '
case might need an else and END at the bottom
referring to a data type as something else can cause errors. For example a numeric like [Sales] = 'Jane Doe'
For example (assuming the result is a string and data item 2 is also a string),
case
when([data item 1] IS NULL)Then('X')
when([data item 1] = ' ')Then('X')
else([data item 2])
end
Also, if you want to show a data item as a different type, you can use CAST

OR Formula in Word document not returning a value

I am working on a document where I need to be able to test multiple options in an if statement to see if one of them are true to decide if a paragraph displays on the document. I have been trying to figure out why my OR formula is not returning a value for me to test and I am not sure why it is not showing anything when it is updating.
I have inserted a field and added a formula within that field that I am hoping will work with my If statement to show the proper paragraph contens.
When I use an Or statement, even one as simple as { OR(1=1) } and update and toggle the field I get no result. From what I have read I should get a 1 or a 0, but I don't seem to get either of these results. The line just ends up blank. When I test it with my If formula it always shows the false result, even when the Or contains a true result.
The formula I am currently working with is:
{ IF{ OR("$event.eventType.name}" = "Birthday", "$event.eventType.name}" =
"Conference" } "Yes" "No" }
If I update and toggle the Or field it shows blank, no result either true or false, and makes the If formula show as false event on results where it should show true. As I mentioned above I even tried setting it to 1=1 and still could not get it to show as true. Not sure if there is something I am missing in working with the formula.
Any suggestions would be appreciated.
It's not clear from your post what $event.eventType.name is. Presumably it's a field generated by an Addin. In that case, you should be able to use something like:
{IF{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0}# 0}> 0 "Yes" "No"}
or:
{={IF{$event.eventType.name}= "Birthday" 1 0}+{IF{$event.eventType.name}= "Conference" 1 0} \# "'Yes',,'No'"}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field constructions are all required. If your fields are a kind of mergefield, you'll need to insert 'MERGEFIELD ' at the start of each one, thus:
{MERGEFIELD $event.eventType.name}

Multiple nested If statement - And Or not working

Using a nested If Statement in Excel I have been trying to obtain results using the following criteria:
within 100 and 75000 Volts but should accept 11; 22; 25; 26; 30; 33; 66
as they will be in kV
Source data is in a table Transformers and the formula is also returning data on two other tables MASTER and META.
I have tried in vain all kinds of IF/AND/OR variants of the following, however I have rarely used nested if statements before so am not at home with the logic. Any help gratefully received !
Thank you
=IF(MASTER!N2="Failed Check 1","Failed Check 1",IF(META!N2="Failed Check 2","Failed Check 2"), IF(OR(Transformers!T2>=110, Transformers!T2<=75000) OR(Transformers!T2=11, Transformers!T2=22, Transformers!T2=25, Transformers!T2=26, Transformers!T2=30, Transformers!T2=33, Transformers!T2=66),"Failed Check 3","Passed Check 3"))
Thank you
It looks like you need an AND as the first term in your OR. The parenthesis also looked incorrect. Once the complexity reaches a certain stage it sometimes helps to compose the formulas in something like Notepad with white-space to display the logic:
=IF(MASTER!N2="Failed Check 1",
"Failed Check 1",
IF(META!N2="Failed Check 2",
"Failed Check 2",
IF(OR(
AND(Transformers!T2>=110, Transformers!T2<=75000),
Transformers!T2=11,
Transformers!T2=22,
Transformers!T2=25,
Transformers!T2=26,
Transformers!T2=30,
Transformers!T2=33,
Transformers!T2=66
),
"Failed Check 3",
"Passed Check 3"
)
)
)
Without linebreaks this is:
=IF(MASTER!N2="Failed Check 1","Failed Check 1",IF(META!N2="Failed Check 2","Failed Check 2", IF(OR(AND(Transformers!T2>=110, Transformers!T2<=75000),Transformers!T2=11, Transformers!T2=22, Transformers!T2=25, Transformers!T2=26, Transformers!T2=30, Transformers!T2=33, Transformers!T2=66),"Failed Check 3","Passed Check 3")))
=IF(MASTER!N2="Failed Check 1","Failed Check 1",IF(META!N2="Failed Check 2","Failed Check 2", IF(OR(Transformers!T2>=110, Transformers!T2<=75000, Transformers!T2=11, Transformers!T2=22, Transformers!T2=25, Transformers!T2=26, Transformers!T2=30, Transformers!T2=33, Transformers!T2=66),"Failed Check 3","Passed Check 3")))
Some problems in your formula:
before the second OR a comma is missing, it should be ),OR(
closing parenthesis of first OR is missing, it should be ...=66)),...
closing parenthesis of IF is missing, your formula should end to )))
+1 you are looking for values between 100 and 75000, this could be done with AND instead of OR
Another approach
To simplify your formula you can place your valid kV values in a range and refer to it; let's call it kVolts (one value per cell, either in one row or in one column)
The simplified formula:
=IF(MASTER!N2="Failed Check 1","Failed Check 1",IF(META!N2="Failed Check 2","Failed Check 2"), IF(OR(AND(Transformers!T2>=110, Transformers!T2<=75000),IFERROR(MATCH(Transformers!T2,kVolts,0)>0,FALSE)) ,"Failed Check 3","Passed Check 3")))
Based on your conditions, I would recommend you implement this one liner which assumes your data is in cell A1.
=IF(OR(AND(A1>=100,A1<=75000),A1=11,A1=22,A1=25,A1=26,A1=30,A1=33,A1=66),TRUE,FALSE)
Although this only returns TRUE or FALSE, which doesn't tell you which check it has passed.

Cognos query calculation - how to obtain a null/blank value?

I have a query calculation that should throw me either a value (if conditions are met) or a blank/null value.
The code is in the following form:
if([attribute] > 3)
then ('value')
else ('')
At the moment the only way I could find to obtain the result is the use of '' (i.e. an empty character string), but this a value as well, so when I subsequently count the number of distinct values in another query I struggle to get the correct number (the empty string should be removed from the count, if found).
I can get the result with the following code:
if (attribute='') in ([first_query].[attribute]))
then (count(distinct(attribute)-1)
else (count(distinct(attribute))
How to avoid the double calculation in all later queries involving the count of attribute?
I use this Cognos function:
nullif(1, 1)
I found out that this can be managed using the case when function:
case
when ([attribute] > 3)
then ('value')
end
The difference is that case when doesn't need to have all the possible options for Handling data, and if it founds a case that is not in the list it just returns a blank cell.
Perfect for what I needed (and not as well documented on the web as the opposite case, i.e. dealing with null cases that should be zero).

Resources