Excel concatenation logical conditions in IF statement - excel

How do I concatenate several conditions in Excel in the IF statement? I want to compare values in 2 different columns but mith more than 1 condition!. IF (condition 1,condition2 ; truevalue;) i dont know the sintaxis for this!

If you use purely native worksheet functions, you have to nest your if statements. It's far from ideal:
=if(condition1,X,if(condition2,Y,if(condition3,Z,A)))
Is like saying:
if (condition1) then X
else if (condition2) then Y
else if (condition3) then Z
else A
You can also define a User Defined Function (UDF) using VBA, but that has some disadvantages associated with it. It adds a lack of transparency for those who don't use VBA. It also makes your workbook a little more "suspicious" since it has embedded macros, which is a turn off for some.
Depending on how complex your conditions are, a UDF still may be the way to go.
Post some real pseudo-code to help identify which side you fall on.

Related

How to get the switch() funciton to say more than one value when two values are the same

I don't know if you consider that excel is a valid programming language to ask in there, but I need this for a project.
In the switch() function, I said to compare the max value of those cells to return the one that coincides, but when two values are the same, it returns the one who is first.
=SWITCH(MAX(J3:J7);J3;"Jugador 1";J4;"Jugador 2";J5;"Jugador 3";J6;"Jugador 4";J7;"Jugador 5")
How could I make it to return "Jugador 2, Jugador 3" instead of just one of them?
I don't figure what function can do something like that. I thought of making something like to functions in one but don't know.
Welcome!
There are several different techniques to accomplish this task. One of them is using a combination of TEXTJOIN() and IF() functions in array formula:
{=TEXTJOIN(",";1;IF(J3:J7=MAX(J3:J7);A3:A7;""))}

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

efficiently testing long boolean expressions in Excel

Ok, lets say that I have two cells in Excel. They each contain a number. I realize that to compare the values of the numbers in these two cells, I can use a simple =[cell1]=[cell2] function. And I also realize that if I want to find the negation of a certain boolean value, I can use the =not function.
My question is simple, is there a more efficient way of coding long boolean formulas? I know in Java I could do something along the lines of ((!(cell1)&&(!(cell2)))||cell3. But in Excel that simple expression turns into something along the lines of =or(and(not(cell1),(notcell2)),cell3). Personally I like the shorter, more compact style of the java code.
Is there a short way to write boolean statements like this in Excel? Or am I doomed to use Excels clunky functions for the simplest of comparisons?
Also, this is a hypothetical question. I am just trying to figure out how to reduce the size of some of my longer boolean expressions. I don't have a specific error, just a lot of frustratingly long formulas.
Well in that case
AND(Not(cell1),NOT(cell2))
Can be replaced by:
=NOT(OR(cell1;cell2))
And, as in most of the cases you can replace AND by * and OR by + all the expression can be written like this:
NOT(cell1+cell2)+cell3

Excel Serial If statements

I'm new to Excel, and I'm struggling with a formula. Essentially, what I'm looking for is to filter a cell through a set of procedures using a formula (this part isn't strict).
For example
Let's say I have a cell, A1. I'm trying to perform different calculations on this based on whether it is between a certain range of values. The problem is, it can be within several ranges.
Pseudo-Code representation
If(A1 > 187.5) {
// Run some code here.
}
If(A1 > 150) {
// Run some code here.
}
NOTE : The above example is only to illustrate the logic of sequential if statements.
Note that I Do not want a nested If statement. I'm just trying to run the same value through various checks. How do I do this in an Excel formula?
The best I can come up with is something like the following.
=(A1>187.5)*<some expression>+(A1>150)*<some expression>+....
The result of this will be some single value. (The straightforward way to get multiple values is to have the individual terms in separate cell.
If you want the result to reflect one among several mutually exclusive outcomes, then you would want to go with:
=(A1>187.5)*<some expression>+(A1>150)*(A1<=187.5)*...etc.
There are many ways to achieve this. One way is to use nested conditions like this:
=IF(Something, do something, IF(something else, do something, do something))
This is good if you want to condensate the formula a bit but arguably leads to more cluttered formulas. According to the FAST-Standard organization, those cases of nested conditions should be replaced by the use of flags. The most simple case would be, for example, where you would be looking for a rebate percentage according to a sales amount. In multiple cells you would have IF conditions evaluating to true only if the value matches that specific range. Then, your formula can be as simple as a SUMPRODUCT of your flags with your rebates percentages.
This is one example, but it can be applied to other cases very well too.
if there is a relationship between the numbers your checking for its very likely you can use
=CHOOSE(FLOOR(A1/160,1)+1,"<160",">160")
Which would put your 150 in the first and leave your 185 in the second

MINUS operation on Array elements

I have an Array say A=(11,23,32,44,56,88,55,14,78,79) And B=(44,56,88,55,14) .Now using VBScript can I perform Set operation MINUS to get an other output say C=(11,23,32,78,79)?
Array A and B can be considered also two Excel columns.
Don't want to use any Looping technique.
Please help
Thanks,
No, vbs or vba cannot directly do a minus operation on two array ( no build-in function )
You must use loops
and here is a good reference for array operations in vba http://www.cpearson.com/excel/vbaarrays.htm
Perhaps it's not a surprise that Dictionaries are the VBScript tool to implement (fake?) sets and operations on them. See this Set demo.
BTW: If you have to deal with more than one thingy, you'll have to loop or ask someone else to loop for you. Insisting on "no loop, please" makes no sense. If 'it works', you may optimize by replacing multiple loops (n x m .. x z) by lookup tables or pre-computations, but you won't understand the problem, if you don't think of loopings.
You can do that in Excel vba if u have named ranges Acol Bcol
Range("C3:C10").FormulaArray = "=Acol-Bcol"

Resources