Excel nested IFs stringing together FALSE values and rendering #VALUE - excel

I have the following nested IFs (I know the comments aren't Excel comments, but using them in my text editor helps me through the logic)
// start by seeing if there is an order date
=IF(
$C46<>"",
//there is an order date. have the parts begun to arrive # P2?
IF(
$D46<>"",
//parts have begun to arrive # P2. Have they finished transferring to Brevard?
IF(
$F46<>"",
// product has finished transferring to warehouse. has it begun to ship?
IF(
$G46<>"",
// product has begun to ship. Has it shipped completely?
IF(
$H46<>"",
// has shipped completely. this ends the cycle
IF(
AND(J$5>=$G46,J$5<=$H46),
"S",
"error - shipped completely"
),
// has NOT shipped completely. Here's where to TODAY() formula comes in
IF(
AND(J$5>=$G46,J$5<=TODAY()),
"S",
"error - began shipping, but not complete"
)
)
// product has NOT begun to ship; HAS completely transferred to Brevard. It's in inventory until shipping begins
IF(
AND(J$5>$F46,J$5<=TODAY()),
"I",
"error - finished transferring to Brevard. in Inventory. Not begun to ship"
)
),
// product has begun assembly, but has not finished transferring to Brevard.
IF(
AND(J$5<=$D46,J$5<=TODAY()),
"A",
"error - assembly has begun, has not finished transferring"
)
),
//there is an order date, but parts have not arrived at P2
IF(
AND(J$5<=C46,J$5<=TODAY()),
"O",
"error - order has been taken, assembly has not begun"
)
),
// there is no order date
""
)
When rendering all this, Excel is stringing together the FALSE values and as a result, they are turned into #VALUE, which ruins the entire formula.
What am I doing wrong? If I remove the FALSE values, it still renders #VALUE. I don't understand how to tell it to do exactly nothing, especially multiple times in one algorithm.

You are having too many ELSE in the formula. Thus, after some debugging this is what you get:
at some point. Thus, the #VALUE appears. In general, the nested if syntax in Excel is like this:
Thus, every new =IF is in the ELSE place. Thus, only one ELSE is written (number 5 from the screenshot above)
IF function – nested formulas and avoiding pitfalls
F9 is a good friend in the evaluation of a big formula. Once you select the formula, select a whole internal formula and press F9 to see the result.

Related

Is there an efficient way to do this excel function

In excel I wanted to differentiate the starting time of a trip into 4 'times of day' (Morning, afternoon, evening, Night)
I made this script, the start_time column consists of time (hh:mm:ss)
=IF(
AND([#[start_time]] >= TIME(20,0,0),
[#[start_time]] <= TIME(23,59,59)
),
"Night",
IF(
AND([#[start_time]] >= TIME(0,0,0),
[#[start_time]] < TIME(6,0,0)
),
"Night",
IF(
AND([#[start_time]] >= TIME(6,0,0),
[#[start_time]] < TIME(12,0,0)
),
"Morning",
IF(
AND([#[start_time]] >= TIME(12,0,0),
[#[start_time]] < TIME(16,0,0)
),
"Afternoon",
"Evening"
)
)
)
)
I was wondering if there is any way to improve this function or make it more easy
Thanks in advance!
So, using vlookup() as suggested:
VLOOKUP(E2,$B$4:$C$8,2,1)
The advantage I find is that the times and the text are easily edited.
Firstly, you can significantly simplify your IF statement by removing the ANDs:
=IF([#[Start Time]]-ROUNDDOWN([#[Start Time]],0) < TIME(6,0,0), "Night",
IF([#[Start Time]]-ROUNDDOWN([#[Start Time]],0) < TIME(12,0,0), "Morning",
IF([#[Start Time]]-ROUNDDOWN([#[Start Time]],0) < TIME(16,0,0), "Afternoon",
IF([#[Start Time]]-ROUNDDOWN([#[Start Time]],0) < TIME(20,0,0), "Evening", "Night")
)
)
The -ROUNDDOWN([#[Start Time]],0) here, allows you to enter a time with or without a date. It is not needed if your times do not also have a date attached.
Using a lookup table instead
The benefit of using a lookup table is that you can easily see and change the cut off times in a single place, rather than searching through multiple formulas.
For Lookups, you should NEVER use VLOOKUP. INDEX/MATCH is better in every way. It is more efficient, less fragile, more versatile, and arguably easier to use, once you are familiar with it.
=INDEX(RefTbl[Times Of Day],MATCH([#[Start Time]]-ROUNDDOWN([#[Start Time]],0),RefTbl[End Time],-1))
Recent Excel version has two functions you might use for this: switch() handles the multiple IF() and LET() gives you the opportunity to create a temporary variable inside your formula. (I would have put this in a comment, but two large URLs make this comment too large)

Combining CONCAT, DATEDIF, and nested IF -getting #VALUE! error

Trying to fill an investment field with Short/Long Term & Capital Gain/Loss. Ending values should be one of the following - STCG, STCL, LTCG, LTCL. (I tried to cut/paste an excel image but it's icky, sorry)
Mini Spreadsheet - Date Acquired (H62), G/L per share (J62), Position (result)
For some investments, the date acquired is Var (for various purchases) or blank (for cash). If it is "Var", the function should return "LT" and skip the DATEDIF function. If the date is blank, the function should be skipped entirely and return blank as there is neither gain nor loss.
=IF($H62="","",CONCAT(IF(OR($H62="Var", DATEDIF($H62,TODAY(),"d")<365),"ST","LT"),IF($J62<0,"CL","CG")))
My original function worked well, except when the Date Acquired field (H62) had "Var", I got a #VALUE! error. I tried to do this with nested IFs and with IFS function, but couldn't get it to work (Problem with this formula error): =IF(H61="","",CONCAT(IF($H61="Var", "LT",IF(DATEDIF($H61,TODAY(),"d")<365),"ST","LT")),IF(J61<0,"CL","CG")))
The logic should be: If date="" then "" else concat LT/ST test and CL/CG test
LT/ST test: If date="Var" then "LT" else if date days before today < 365,"ST" else "LT"
CL/CG test: If gain per share <0 "CL" else "CG" (working)
Please help! I could add a hidden column (I'd rather not) or do the whole thing with nested IFs or IFS but I'd have to repeat arguments and that's sloppy & asking for trouble.

Using a nested IF statement to simulate battery but need to compute actual values not comments

Trying to come up with a nested IF statement that works within a specified limit (battery state of charge) taking the necessary inputs over time.
[Sample Data Sheet]
My attempt to formulate for the State of charge operation is given below
= IF(AND(D5+A6-B6>=0.2*$G$1, D5+A6-B6<=0.95*$G$1), D5+A6-B6,0)
= IF(AND(D5+A6-B6<0.2*$G$1), D6= 0.2*$G$1+(D5+A6-B6).
= IF(AND(D5+A6-B6>0.95*$G$1), D6= 0.95*$G$1.
=IF(D5+A6-B6<=0.2*$G$1), 0.2*$G$1+(D5+A6-B6), IF(AND(D5+A6-B6>=0.2*$G$1, D5+A6-B6<=0.95*$G$1), D5+A6-B6,0), IF(D5+A6-B6>=0.95*$G$1), 0.95*$G$1)))
=IF(D5+A6-B6>=0.95*$G$1), 0.95*$G$1, IF(AND(D5+A6-B6>=0.2*$G$1, D5+A6-B6<=0.95*$G$1), D5+A6-B6,0), IF(D5+A6-B6<=0.2*$G$1), 0.2*$G$1+D5+A6-B6)))
I keep getting errors that my formulae are incorrect, please help for both state of charge and spare generation equations.
Thanks
Below is the link to the sample sheet that I have created.
https://drive.google.com/file/d/1kmhkBybMg18Odrow5jElcEt8RcLXqCFH/view?usp=sharing
I'm Assuming the G1 value is 1 or more than 1. Also, I'm also assuming the formula is for E5 cell. Here is the proposed solution.
=IF((D5+A6-B6)<(0.2*$G$1),(0.2*$G$1)+(D5+A6-B6),IF((D5+A6-B6)>(0.95*$G$1), (0.95*$G$1), IF(AND((D5+A6-B6)>=(0.2*$G$1), (D5+A6-B6)<=(0.95*$G$1)), (D5+A6-B6),"not in range")))
Here is the same equation expanded ( to see the logic and sequence ) :
=IF((D5+A6-B6)<(0.2*$G$1) , (0.2*$G$1)+(D5+A6-B6),
IF((D5+A6-B6)>(0.95*$G$1) , (0.95*$G$1),
IF(AND( (D5+A6-B6)>=(0.2*$G$1),(D5+A6-B6)<=(0.95*$G$1)) , (D5+A6-B6),"not in range"
)
)
)
Please have a check.

Nested IF statement returning false

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

IF function for specific text strings

I am trying to write a formula that takes a word and process it through a IF function in excel, The Values are list in the formula. My issue right now is the fact that I have Large, X-Large and 1X-Large text. The X-Large and 1X-Large are unique strings and need the IF function to be able to differentiate the two.
Here is what i have so far.
=if(or(isnumber(search("Small",af2)),ISNUMBER(SEARCH("Medium",AF2)),ISNUMBER(SEARCH("Large",AF2)),,ISNUMBER(SEARCH("X-Large",AF2))),"Small",or(isnumber(search("1X-Large",af2)),isnumber(search("2X-Large",af2)),isnumber(search("3X-Large",af2)),isnumber(search("4X-Large",af2))),"1X-Large")
I cant understand why it's showing an error and only displays small when it works.
All help is appreciated
Your current formula shouldn't work, it should be giving you an error about having too many arguments. A breakdown of your function:
=if(
or(isnumber(search("Small",af2)),ISNUMBER(SEARCH("Medium",AF2)),ISNUMBER(SEARCH("Large",AF2)),,ISNUMBER(SEARCH("X-Large",AF2))),
"Small",
or(isnumber(search("1X-Large",af2)),isnumber(search("2X-Large",af2)),isnumber(search("3X-Large",af2)),isnumber(search("4X-Large",af2))),
"1X-Large"
)
You cannot use 4 parameters in an IF. You need to have a maximum of 3. Maybe what you meant was:
=if(
or(isnumber(search("Small",af2)),ISNUMBER(SEARCH("Medium",AF2)),ISNUMBER(SEARCH("Large",AF2)),,ISNUMBER(SEARCH("X-Large",AF2))),
"Small",
IF(
or(isnumber(search("1X-Large",af2)),isnumber(search("2X-Large",af2)),isnumber(search("3X-Large",af2)),isnumber(search("4X-Large",af2))),
"1X-Large"
)
)
But that doesn't solve your issue about the X-Large part. To cater for that, you can check whether the X-Large series exist first, then the others.
=IF(
OR(ISNUMBER(SEARCH("1X-Large",AF2)),ISNUMBER(SEARCH("2X-Large",AF2)),ISNUMBER(SEARCH("3X-Large",AF2)),ISNUMBER(SEARCH("4X-Large",AF2))),
"1X-Large",
IF(
OR(ISNUMBER(SEARCH("Small",AF2)),ISNUMBER(SEARCH("Medium",AF2)),ISNUMBER(SEARCH("Large",AF2)),ISNUMBER(SEARCH("X-Large",AF2))),
"Small"
)
)
Although you can make it shorter with this:
=IF(
OR(ISNUMBER(SEARCH({"1X-Large","2X-Large","3X-Large","4X-Large"},AF2))),
"1X-Large",
IF(
OR(ISNUMBER(SEARCH({"Small","Medium","Large","X-Large"},AF2))),
"Small"
)
)
In one line...
=IF(OR(ISNUMBER(SEARCH({"1X-Large","2X-Large","3X-Large","4X-Large"},AF2))),"1X-Large",IF(OR(ISNUMBER(SEARCH({"Small","Medium","Large","X-Large"},AF2))),"Small"))

Resources