Excel if statement parameters - excel

I have two individual statements that work individually
=IF(C6=1,(IFERROR(HLOOKUP(C4,list1,IF(C5"apple",2,IF(C5="orange",3,
IF(C5="plum",4,IF(C5="grape",5,IF(C5="banana",6,"")))))),"")))
and
=IF(C6=2,(IFERROR(HLOOKUP(C4,list2,IF(C5"apple",2,IF(C5="orange",3,
IF(C5="plum",4,IF(C5="grape",5,IF(C5="banana",6,"")))))),"")))
But when i combine them both into if statements,
=IF(C6=1,(IFERROR(HLOOKUP(C4,list1,IF(C5="apple",2,IF(C5="orange",3,
IF(C5="plum",4,IF(C5="grape",5,IF(C5="banana",6,"")))))),""))),
IF(C6=2,(IFERROR(HLOOKUP(C4,list2,IF(C5="apple",2,IF(C5="orange",3,
IF(C5="plum",4,IF(C5="grape",5,IF(C5="banana",6,"")))))),"")))
The Data Look like this
Data sheet
I get a '#Value!' Error, parentheses seem to be in place, not sure whats yielding this error.

OK, you need to do some reading on the HLOOKUP function, LOOKUP function amd CHOOSE function.
This formula follows the rules of your sample formula(s) (such as they are) and should serve to simplify matters by avoiding repetition. Note that "apple","banana","grape","orange","plum" are in alphabetical order.
=IFERROR(HLOOKUP(C4, CHOOSE(C6, List1, List2, List1),
LOOKUP(C5, {"apple","banana","grape","orange","plum"}, {2,6,5,3,4}),
FALSE), "")
If you require more assistance, please edit your original question to include sample data and expected results.

Related

Excel's LAMBDA with a "kind of" composite function

Ever since I learnt that Excel is now Turing-complete, I understood that I can now "program" Excel using exclusively formulas, therefore excluding any use of VBA whatsoever.
I do not know if my conclusion is right or wrong. In reality, I do not mind.
However, to my satisfaction, I have been able to "program" the two most basic structures of program flow inside formulas: 1- branching the control flow (using an IF function has no secrets in excel) and 2- loops (FOR, WHILE, UNTIL loops).
Let me explain a little more in detail my findings. (Remark: because I am using a Spanish version of Excel 365, the field separator in formulas is the semicolon (";") instead of the comma (",").
A- Acumulator in a FOR loop
B- Factorial (using product)
C- WHILE loop
D-UNTIL loop
E- The notion of INTERNAL/EXTERNAL SCOPE
And now, the time of my question has arrived:
I want to use a formula that is really an array of formulas
I want to use an accumulator for the first number in the "tuple" whereas I want a factorial for the second number in the tuple. And all this using a single excel formula. I think I am not very far away from succeeding.
The REDUCE function accepts a LET function that contains 2 LAMBDAS instead of a single LAMBDA function. Until here, everything is perfect. However, the LET function seems to return only a "single" function instead of a tuple of functions
I can return (in the picture) function "x" or function "y" but not the tuple (x,y).
I have tried to use HSTACK(x,y), but it does not seem to work.
I am aware that this is a complex question, but I've done my best to make myself understood.
Can anybody give me any clues as to how I could solve my problem?
Very nice question.
I noticed that in your attempts you have given REDUCE() a single constant value in the 1st parameter. Funny enough, the documentation nowhere states you can't give values in array-format. Hence you could use the 1st parameter to give all the constants in (your case; horizontal) array-format, and while you loop through the array of the 2nd parameter you can apply the different types of logic using CHOOSE():
=REDUCE({0,1},SEQUENCE(5),LAMBDA(a,b,CHOOSE({1,2},a+b,a*b)))
This way you have a single REDUCE() function which internal processes will update the given constants from the 1st parameter in array-form. You can now start stacking multiple functions horizontally and input an array of constants, for example:
=REDUCE({0,1,100},SEQUENCE(5),LAMBDA(a,b,CHOOSE({1,2,3},a+b,a*b,a/b)))
I suppose you'd have to use {0\1} and {1\2} like I'd have to in my Dutch version of Excel.
Given your accumulator:
Formula in A1:
=REDUCE(F1:G1,SEQUENCE(F3),LAMBDA(a,b,CHOOSE({1,2},a+b,a*b)))

Excel nested if statement error how to fix?

trying to do a nested if :
=IF([Years of Service]>10,'Data Tables'!$B$11,"if([years of service]>5,'Data Tables'!$b$10)")
getting a spill error.
You don't indicate what you want to do and I'm not sure exactly what you really want to do.
But it seems your formula is within a Table. That being the case, formulas that output arrays, when placed in a Table will produce the #SPILL! error.
If, what you want to do, is to compare the Years of Service from the same row as the formula, then you need to refer just to that row, so as to not output an array.
eg:
=IF([#[Years of Service]]>10,'Data Tables'!$B$11,
IF([#[Years of Service]]>5,'Data Tables'!$B$10,
IF([#[Years of Service]]>1,'Data Tables'!$B$9,
'Data Tables'!$B$8)))
If you want something else, then you'll need to provide more detail.

Nested IF statements with VLOOKUPs

I'm trying to created a nested IF statement that says, for example, IF A2 is equal to x, x, x posting codes then pull data from the revenue column, IF A2 is equal to y, y, y posting codes then pull data from Bad Debt column and so on for 6 different possible results. Only 3 of the 6 are VLOOKUPs. The other 3 are just if A2=Z then "1024".
I will copy what code I currently have, but it's not pretty. Any help is appreciated. Thank you.
=IF(G2="100",G2="101",G2="102",G2="105",G2="106",G2="170",G2="171",G2="173",G2="200",G2="210",G2="220",G2="230",G2="250",G2="300",G2="301",G2="302",G2="304",G2="305",G2="306",G2="307",G2="308",G2="309",G2="310",G2="312",G2="313",G2="314",G2="315",G2="316",G2="317",G2="318",G2="319",G2="320",G2="321",G2="322",G2="323",G2="324",G2="325",G2="326",G2="327",G2="328",G2="329",G2="330",G2="331",G2="332",G2="333",G2="334",G2="335",G2="336",G2="337",G2="338",G2="339",G2="340",G2="341",G2="342",G2="343",G2="344",G2="345",G2="346",G2="360",G2="370",G2="372",G2="379",G2="382",G2="383",G2="385",G2="390",G2="402",G2="403",G2="404",G2="405",G2="414",G2="415",G2="416",G2="417",G2="418",G2="419",G2="420",G2="421",G2="425",G2="427",G2="428",G2="429",G2="440",G2="441",G2="442",G2="443",G2="444",G2="445",G2="447",G2="472",G2="477",G2="480",G2="501",G2="600",G2="700",G2="800",G2="900",vlookup('AR Credit'!A2,Guarantors!A:D,3,FALSE),IF(G2="347",G2="384",G2="399",G2="406",G2="499",G2="801",vlookup('AR Credit'!A2,Guarantors!A:D,5,FALSE),IF(G2="348",G2="354",G2="355",G2="357",G2="377",G2="601",vlookup('AR Credit'!A2,Guarantors!A:D,4,FALSE),IF(G2="120",G2="150",G2="151",G2="152",G2="153",G2="154","1051",IF(G2="400","1385",IF(G2="500","2036",IF(G2="172","3783","Null"))))))))
One way of fixing your issue is by using OR, specifically wrapping your cases in it like in this example:
=OR(G2="100",G2="101",G2="102",G2="105")
This will result in TRUE if any of conditions is met, otherwise FALSE.
There are numerous errors with your formula. You could get it working by following Zipa's answer and using the OR function. However, it would be a nightmare to maintain if anything changes in future.
I would recommend creating a look up table for the values and results. It could then be queried like so:
=IF(COUNTIFS($E$2:$E$98,$A2)>0,$E$1,
IF(COUNTIFS($F$2:$F$98,$A2)>0,$F$1,
IF(COUNTIFS($G$2:$G$98,$A2)>0,$G$1,
IF(COUNTIFS($H$2:$H$98,$A2)>0,$H$1,
IF(COUNTIFS($I$2:$I$98,$A2)>0,$I$1,
IF(COUNTIFS($J$2:$J$98,$A2)>0,$J$1,
IF(COUNTIFS($K$2:$K$98,$A2)>0,$K$1,"NULL")
)
)
)
)
)
)
See the image below for illustration:
Where I have put "Opt1", "Opt2" in the results row, you can put your VLOOKUPs (although I would recommend INDEX/MATCH instead) or your hard coded values.
This way, you can easily see (and modify) which group each code is in. Even adding more groups wouldn't be too difficult.
Obviously, you could move the table onto a different sheet if you wished.

Conditional standard deviation? STD.S with IF not working; trying to apply to data after using AVERAGEIFS with same conditions

(I am working with a Spanish interface, so please forgive the code in Spanish (the ; is a , in English, PROMEDIO.SI.CONJUNTO is AVERAGEIFS, INDICE is INDEX, FILA is ROW, DESVEST.M is STD.S, SI is IF, Y is AND).
I have look through all the threads about a "stvifs" (which Excel really should think about in the future!) and I am still unable to apply what I've learned to my data, even though it seems exactly like what I've seen! After successfully applying the following to my data:
=PROMEDIO.SI.CONJUNTO(E:E;A:A; INDICE(I:I; 2+(FILA(1:1)-1));D:D; 1;F:F; "BC")
I automatically got my column with "BC" and their means for each participant. (I have four conditions in total.) Now I want the SD for the SAME conditions. I tried applying this code as an array formula:
{=DESVEST.M(SI(Y((A:A)=INDICE(I:I; 2+(FILA(1:1)-1));(D:D)=1;(F:F) ="BC");E:E))}
I get a #DIV/0! error. I debugged the formula, and it is giving me FALSE as a result within the STD.S, hence the error. But what I don't understand is why it's not giving me an array with all the values in the column E that comply with the given conditions! The interesting thing is that when I apply the formula normally, it gives me STD.S(E:E) correctly, so I feel that this should work! I have done something similar with other data, but there weren't multiple conditions. Please help!
The formula would look something like this (in English) but not sure about ROW part and can't test it properly without some sample data:-
=STDEV.S(IF((A1:A10=INDEX(I1:I10, 2+ROW(1:1)-1))*(D1:D10=1)*(F1:F10 ="BC"),E1:E10))
Have limited it to 10 rows to make debugging easier with 'Evaluate Formula'.
This gives the stdev (sample) of the three shaded cells:-

INDIRECT() returns #VALUE! unexpectedly

Background: I'm using Excel functions to parse a lot of data out, essentially creating a flexible pivot table. It sorts a lot of race timing data by car, etc. In this portion of the sheet, I'm searching for the minimum segment times for each car. The rest of the sheet avoids macros and VBA so I'd like to avoid that here.
Issue: My formula worked when there are no zeros, but sometimes there are zeros that I need to exclude. My array formula is pretty complicated, but the change I made that broke it is this:
OLD (working):
{=min(if(car_number = indirect("number_vector"), indirect("data_vector")))}
NEW (non-working):
{=min(if(and(car_number = indirect("number_vector"),not(0=indirect("data_vector"))), indirect("data_vector")))}
I am using INDIRECT() with this exact argument several times in the formula. However, in this particular instance (inside the NOT()), it returns #VALUE! instead of {data1;...;datan}. Please see the screencaps below.
Before evaluation:
After evaluation:
I suspect that your AND function might be a problem - AND only returns a single result not an array of results as required, try using multiple IFs like this
=min(if(car_number = indirect("number_vector"),IF(indirect(data_vector)<>0, indirect(data_vector))))
Note that I also used <> rather than using NOT
Are data vector and number vector the same size and shape? (both vertical?)
why are there quotes around one but not the other?

Resources