If-Else ladder in Excel To sort data - excel

I was doing R&D on Excel. And wanted to use If-else ladder in column of excel.
Let's say I have a 2 columns and I calculated the difference between the two columns. Now, If the difference is between a range of (-5 to +5), if should display something or if Difference greater than 5, it should display something and for rest i.e. difference < -5, should display something else.
I tried and came up with this
=IF("H2>5",<something1>, IF("H2<5",<something2>))
How to put the range part in this if-else ladder? Also the above If else is not giving value but the result is turning out to be #VALUE.
Thanks for your help.

Try
=IF(H2<-5,"Negative",IF(H2<=5,"In Range","Positive"))

There could be 3 possibilities only, 1 the answer is between -5 to 5 inculdining -5 and 5. 2 greater then 5. 3 smaller than -5. so this should work
=IF(AND(H2>=-5,H2<=5),"between -5 &5",IF(H2<-5,"Smaller than-5",IF(H2>5,"greater than 5 ")))
let me know if this is what is required.

Related

Find if a entry has negative value in any column in excel

OBJECTID E201701 G201701 E201702 G201702 E201703 G201703 E201704 G201704
1 2 5 6 5 -1 NaN 6 5
I want to find if a particular entry (i.e. objectid) has negative value in any of variable (e201701, etc). I tried;
IF(AND(B2>0,C2>0,D2>0,E2>0,F2>0,G2>0,H2>0),1,0)
but it just give me 1 irrespective.
Your formula is asking "Is thisCell > (Greater than) thisCell?" Try using this. Also, change the AND to an OR because AND is going to check all values and if ALL of them are returning true then it will return as such. OR will check EACH individually.
IF(OR(B2<0,C2<0,D2<0,E2<0,F2<0,G2<0,H2<0),1,0)
Which is asking "Is thisCell > (Less than) thisCell?"
If you use excel 2013 or later then you can use below formula. This formula will also give you position number where the negative value is. As your sample data it will return 6 because negative value is in 6th position.
=AGGREGATE(15,6,COLUMN(A1:I1)/(A1:I1<0),1)
For sample same results as #xTwisteDx but shorter and easy to extend (eg to include G201704 just change H to I) :
=1*(MIN(B2:H2)<0)

Excel sum based on matrix condition and multiple criteria

Following from the example here I'm trying to add additional conditions to a sum formula. I've represented an example below:
The output that I'm looking for for example for Jan 2017 is
2017
1
UP A 1
UP B 6
UP C 6
DOWN A 1
DOWN B 8
DOWN C 7
I tried with the following formula:
=MMULT(--($B$17:$C$17="X"),MATCH(1,($A23=$C$2:$C$14)*(C$21=$A$2:$A$14)*(C$22=$B$2:$B$14)*($E$2:$E$14=$D$2:$D$14),0))
but I get a N/A value.
Does anyone know it if is possible to do it?
In your first example the number of rows in array1 and number of columns in array2 were equal, five. Here you have two columns and 13 rows. That they are unequal here is part (all) of the reason why you are having an issue.
Also your match function is returning a Boolean not an array
I have a way to do this using matrix condition and multiple criteria but had to change problem up a bit, see photo for example:
{=MMULT(--(D18:P18="x"),E$2:E$14*(--(A$2:A$14=$C$21)*--(B$2:B$14=$C$22)*--(C$2:C$14=A24)))"
https://i.stack.imgur.com/FEvgR.png
You can create a formula to fill the second matrix with X's see below
=IF(OR(INDIRECT("D"&VALUE(D20))=$A$18,INDIRECT("D"&VALUE(D20))=$B$18),"X","")
https://i.stack.imgur.com/4rS4L.png
That being said I don't think this is particularly efficient as you are treating the one of the matrixes as a all 1's so you basically just adding an extra criteria / Boolean with added complexity....that being said u asked for this specifically and I believe that I have delivered that LOL
Just add two SUMIFS together.
=SUMIFS($E$2:$E$14, $A$2:$A$14, C$21, $B$2:$B$14, C$22, $C$2:$C$14, $A23, $D$2:$D$14, IF(INDEX($B$17:$C$19, MATCH($B23, $A$17:$A$19, 0), 1)="x", $B$16))+
SUMIFS($E$2:$E$14, $A$2:$A$14, C$21, $B$2:$B$14, C$22, $C$2:$C$14, $A23, $D$2:$D$14, IF(INDEX($B$17:$C$19, MATCH($B23, $A$17:$A$19, 0), 2)="x", $C$16))

Using a subset of excel entries for calculation

Assume that you have 5 cells with values:
[12, 23, 50, 89, 95]
and you are interested in finding the average of the four largest entries (that is drop 12 because it is the smallest).
I wonder how one can do that in excel?
You can get the average of the largest 4 from 5 with this formula
=AVERAGE(LARGE(A1:E1,{1,2,3,4}))
that will only average 4 values even if there are duplicates
Generically if you might have a variable number of values then to average without the smallest value you can use this version
=(SUM(Range)-MIN(Range))/(COUNT(Range)-1)
again that will work OK with duplicates - of course there must be at least 2 numbers in the range
You can use AVERAGEIF(range,condition)
So in your case, it will be AVERAGEIF(A1:E1,">"&MIN(A1:E1))
Hope this helps..
Use =LARGE to get the วน-th largest value then use =SUMIF to add if the value is larger than the n-th value!
In pseudocode something like this: =SUMIF(data >= LARGE(range, n))/n, sorry it's been a while since I used excel. `

IF function with 3 conditions

I'm looking to create a formula with 3 conditions. It is currently only working with 2 conditions. Here's what I'm looking for:
E9 has a number
If the number is 21+ then I want it to show Text 1
If the number is between 5 and 21, then I want it to show Text 2
If the number is below 5, then I want it to show Text 3
This is what I currently have:
=IF(E9>21,"Text 1",IF(E9<21,E9>5,"Text 2")
When I try and add the final condition, it gives me an error that I've entered too many arguments for this function. When the number is below 5 it shows False.
I would prefer a solution that does not use VLOOKUP.
I'm not understanding why it's saying this is not allowed, I have another IF function with 5 nested formulas that works just fine.
You can do it this way:
=IF(E9>21,"Text 1",IF(AND(E9>=5,E9<=21),"Test 2","Text 3"))
Note I assume you meant >= and <= here since your description skipped the values 5 and 21, but you can adjust these inequalities as needed.
Or you can do it this way:
=IF(E9>21,"Text 1",IF(E9<5,"Text 3","Text 2"))
Using INDEX and MATCH for binning. Easier to maintain if we have more bins.
=INDEX({"Text 1","Text 2","Text 3"},MATCH(A2,{0,5,21,100}))
=if([Logical Test 1],[Action 1],if([Logical Test 2],[Action 1],if([Logical Test 3],[Action 3],[Value if all logical tests return false])))
Replace the components in the square brackets as necessary.
You can simplify the 5 through 21 part:
=IF(E9>21,"Text1",IF(E9>4,"Text2","Text3"))

Excel 2003: Better workaround for 10 if statements

I have a very rough workaround for 10 statements using a combination of 2 cells, as follows
Cell 1 (O2)
=IF(C2="TW2-OUT",VLOOKUP($D2,Players,8,FALSE)+VLOOKUP($D2,Players,9,FALSE),IF(C2="TW2-IN",IF($D2="","",VLOOKUP($D2,Players,10,FALSE)),IF(C2="Playing",IF($D2="","",VLOOKUP($D2,Players,8,FALSE)+VLOOKUP($D2,Players,9,FALSE)+VLOOKUP($D2,Players,10,FALSE)),IF(C2="IN1OUT2",VLOOKUP($D2,Players,9,FALSE)+VLOOKUP($D2,Players,10,FALSE),IF(C2="TW1-OUT",IF($D2="","",VLOOKUP($D2,Players,8,FALSE)),IF(C2="TW1-IN",IF($D2="","",VLOOKUP($D2,Players,9,FALSE)+VLOOKUP($D2,Players,10,FALSE)),IF(C2="TW3-OUT",VLOOKUP($D2,Players,8,FALSE)+VLOOKUP($D2,Players,9,FALSE)+VLOOKUP($D2,Players,10,FALSE),0)))))))+P2
Cell 2 (P2)
=IF(C2="TW3-IN",IF($D2="","",VLOOKUP($D2,Players,11,FALSE)),IF(C2="IN2OUT3",VLOOKUP($D2,Players,10,FALSE),IF(C2="IN1OUT3",VLOOKUP($D2,Players,9,FALSE)+VLOOKUP($D2,Players,10,FALSE),0)))
Is there a better way of doing this. I have read via a Google search about using a table approach with an array to achieve the same effect. However, in my case the status of a player determines the score of a player and this complicates things for me. Here are the 10 possible statuses (if statements) broken down as follows with how scored are calculated:
TransferStatuses Cols
Playing 8+9+10+11
TW1-IN 9+10
TW1-OUT 8
TW2-IN 10+11
TW2-OUT 8+9
TW3-IN 11
TW3-OUT 8+9+10
IN1OUT2 9
IN1OUT3 9+10
IN2OUT3 10
8 = ColK (Transfer Window 0)
9 = ColL(Transfer Window 1)
10 = ColM (Transfer Window 2)
11 = ColN(Transfer Window 3)
The 'score' array will be along the lines as follows:
=VLOOKUP(C2,$S$2:$T$11,2,FALSE)
The problem is that I don't know how to put it all together to make it work, i.e. I have to extend my formula to 300 cells but I don't know how to implement it so that the array calculates the scores correctly for each player?
Can someone help?
If I understand you correctly I would approach it like this:
Set up a matrix of binary values that specify, for each status, which columns should be added up. Use OFFSET and MATCH to look up the status for each data row and return the array/range of binary values, and SUMPRODUCT to sum it all up. See screenshot:

Resources