Excel formula using more if - excel

I have a problem with my nested if condition as an Excel formula. I know it would be easier by using VBA, but I have to do it this way.
This is my formula, but it returns FALSE:
=IF(D:D="SUPER";IF(AND(AA:AA="0";AA:AA="1");"V";IF(AA:AA="3";"R";"O")))
The D:D column has 3 filters, I have to apply the same formula with each filter.
The AA:AA column has the following conditions:
- if 0 and 1 -> V
- if 3 -> R
- if anything else -> O
I don't know why it doesn't work, but I would appreciate any advice!
This will return R, because there is 3 in there
enter image description here

I think this is more a matter of prioritizing logic flow. It seems that at least a single occurrence of SUPER with 3 supersedes the rest. The next priority would be SUPER with 0 and SUPER with 1 (both must occur). If none of those apply, default to O.
=if(countifs(d:d, "super", aa:aa, 3), "R", if(not(and(countifs(d:d, "super", aa:aa, 0), countifs(d:d, "super", aa:aa, 1))), "O", "V"))
'with semi-colons
=if(countifs(d:d; "super"; aa:aa; 3); "R"; if(not(and(countifs(d:d; "super"; aa:aa; 0); countifs(d:d; "super"; aa:aa; 1))); "O"; "V"))

=IF(COUNTIFS(D:D;"super";AA:AA;3)<>0;"R";IF(COUNTIFS(D:D;"super";AA:AA;1)*COUNTIFS(D:D;"super";AA:AA;0)=0;"O";"V"))
The order of the criteria was wrong, also you generally can't refer to entire columns in the way you did. This formula first checks whether there's any cell with the value 3. Then if there isn't it multiplies the count of 1s and 0s to check whether there are both numbers present.

Related

How to color max. 2 consecutive values in Excel without using VBA?

I'm out of idea how I could format consecutive same (respectively only even) values in Excel tables without using VBA.
The conditional formatting shall color only consecutive values and only
all 0s or all even values, when there are not more than 2.
A: ID
B: binary
C: counting
1
1
1
2
0
2
3
0
2
4
1
3
5
0
4
6
0
4
7
0
4
8
1
5
9
1
5
I tried to format with: =COUNTIF(C1:C9, C1) < 3, but then it also colors the 1s and C6:C7, eventho there are more than 2.
I also tried =AND( COUNTIF(C1:C9,C1) < 3, ISEVEN(C1:C9) ) but then it colors nothing.
I could replace the 0s with empty cells so I could check ISEMPTY(B1:B9) but it again colors nothing. Using $ to set absolute changes nothing as well.
Formating duplicates also colors triplets, which also doesn't work for me.
=OR(COUNTIF($C$1:$C$9,C1) = 1, COUNTIF($C$1:$C$6,C1) = 2) works so far, but also colors the 1s (uneven).
=AND(OR(COUNTIF($C$1:$C$9,C1) = 1, COUNTIF($C$1:$C$6,C1) = 2), ISEVEN($C$1:$C$9)) doesn't work.
=AND(OR(COUNTIF($C$1:$C$9,C1) = 1, COUNTIF($C$1:$C$6,C1) = 2), $B$1:$B$9 <> 1) doesn't work as well.
My only solution so far is using 2 formating rules:
color =OR(COUNTIF($C$1:$C$9,C1) = 1, COUNTIF($C$1:$C$6,C1) = 2)
do not color =$B$1:$B$9 = 1
but I think it is terrible.
I worked on it for some hours, maybe I'm missing something really obvious.
I'm not allowed to use VBA, therefore this is ot an option.
EDIT: My 2.rule-solution can be simplificed with:
color =COUNTIF($C$1:$C$9,C1) < 3
do not color =$B$1:$B$9 = 1
I'm still confused why combining both doesn't work:
AND(COUNTIF($C$1:$C$9,C1) < 3; $B$1:$B$9 <> 1)
EDIT2: I know why it didn't work. Don't check <>1 with absolute value-range $B$1$:$B$9
Solution: B1 <> 1 then it loops through.
Now combining both works:
=AND( COUNTIF($C$1:$C$9, C1) < 3, B1 <> 1)
I can't see an easy answer for the binary numbers. You have two cases:
(1) Current cell is zero, previous cell is 1, next cell is zero and next cell but one is 1.
(2) Current cell is zero, previous cell is zero, previous cell but one is 1, next cell is 1.
But then the first pair of numbers is a special case because there is no previous cell.
Strictly speaking the last pair of numbers is a special case as well because there is no following cell.
=OR(AND(ROW()=1,B$1=0,B$2=0,B$3=1),AND(ROW()=2,B$1=0,B$2=0,B$3=1),AND(B1=0,B1048576=1,B2=0,B3=1),AND(B1=0,B1048576=0,B1048575=1,B2=1))
where I have used the fact that you are allowed to wrap ranges to the end of the sheet (B1048576) in conditional formatting.
Adding the condition for the case where there there are two zeroes at the end of the range:
=OR(AND(ROW()=1,B$1=0,B$2=0,B$3=1),
AND(ROW()=2,B$1=0,B$2=0,B$3=1),
AND(B1=0,B1048576=1,B2=0,OR(B3=1,B3="")),
AND(B1=0,B1048576=0,B1048575=1,OR(B2=1,B2="")))
Even this could go wrong if there was something in the very last couple of rows of the sheet, so I suppose to be absolutely safe:
=OR(AND(ROW()=1,B$1=0,B$2=0,B$3=1),
AND(ROW()=2,B$1=0,B$2=0,B$3=1),
AND(Row()>1,B1=0,B1048576=1,B2=0,OR(B3=1,B3="")),
AND(Row()>2,B1=0,B1048576=0,B1048575=1,OR(B2=1,B2="")))
Shorter:
=OR(AND(ROW()<=2,B$1+B$2=0,B$3=1),
AND(B1+B2=0,B1048576=1,OR(B3=1,B3="")),
AND(B1+B1048576=0,B1048575=1,OR(B2=1,B2="")))
Not the cleanest wat but it works. You only need to move your data 1 row below, so headers would be in row 2 and data in row 3 for this formula to work:
=IF(AND(B3=B4,B3<>B5),IF(AND(B4=B3,B4<>B2),TRUE,FALSE),IF(AND(B3=B2,B3<>B1),IF(AND(B3=B4,B3<>B5),FALSE,TRUE),FALSE))
How about this approach (Office 365):
=LET(range,B$1:B$9,
s,IFERROR(TRANSPOSE(INDEX(range,ROW()+SEQUENCE(5,,-2))),1),
t,TEXTJOIN("",,(s=INDEX(range,ROW()))*ISEVEN(s)),
IFERROR(SEARCH("0110",t)<4,IFERROR(SEARCH("010",t)=2,FALSE)))
It creates an array s of 5 values starting point is the current row of the range, adding the 2 values above and below. If the value is out of range it will replace the error with a 1.
The array s is checked for being even (TRUE/FALSE, IFERROR created values are uneven) and the values to equal the value of the current row of the range (TRUE/FALSE).
These two booleans are multiplied creating 1 for both values being TRUE, else 0.
These values are joined and checked for 2 consecutive 1's (surrounded by 0) to be found in the 2nd or 3rd position of the range (this would be the case if two even consecutive equal numbers are found),
if it errors it will look if a unique even number is found (1 surrounded by 0 in 2nd position).
PS I'm unable to test if conditional formatting allows you to type the range as B:B instead of B$1:B$9 (working from a mobile) but that would make it more dynamical, because that way you can easily expand the conditional range.

Aggregate function (small) returns zeros rather than the smallest values

I am using excel's aggregate (small) function to find the smallest value for each name that appears in a column. The issue is that the formula below simply returns 0s everywhere there is a value in B.
The formula I am using is
=IF($B2<>"", AGGREGATE(15,7, ($B:$B)*($A2=$A:$A)*($B2<>""), 1), "")
where B contains the data I want the smallest value from and A contains identifying strings.
I appreciate any help you can lend!
You want to divide by the criteria:
=IF($B2<>"", AGGREGATE(15,7, ($B:$B)/(($A2=$A:$A)*($B:$B<>"")), 1), "")
Whenever ($A2=$A:$A) or ($B2<>"") is FALSE it will return 0 and anything multiplied by 0 is 0 and as such the smallest value is 0.
By dividing by the criteria we throw an #DIV/0 error which the 7 in the AGGREGATE's second criterion forces the formula to ignore and as such we only get the smallest of what returns TRUE or 1 in both Boolean. 1*1=1.
But one more thing. AGGREGATE is an array type formula so limiting the to only the data will speed it up.
=IF($B2<>"", AGGREGATE(15,7, ($B$1:INDEX($B:$B,MATCH("zzz",$A:$A)))/(($A2=$A$1:INDEX($A:$A,MATCH("zzz",$A:$A)))*($B$1:INDEX($B:$B,MATCH("zzz",$A:$A))<>"")), 1), "")
As per your comment:
=IF($B2 = AGGREGATE(15,7, ($B:$B)/(($A2=$A:$A)*($B:$B<>"")), 1),AGGREGATE(15,7, ($B:$B)/(($A2=$A:$A)*($B:$B<>"")), 1), "")

How to do a quadruple IF in excel

I would like to make an IF statement in Excel where if a certain cell equals to O, V, G or U another cell outputs 1, 2, 3 or 4 respectively.
I can't find any solution only, sorry.
There's probably a cleaner way to do this... but I'm not an excel expert.
If A1 is the cell you are checking to contain O V G or U:
=IF(A1="O", 1, IF(A1="V", 2, IF(A1="G", 3, IF(A1="U", 4, ""))))
The syntax of excel's if is: If(condition, valueIfConditionIsTrue, valueIfConditionIsFalse)
This is how excel interprets the command in a way that's easier for us to understand:
if A1 == "O":
output = 1
else:
if A1 == "V":
output = 2
else:
if A1 == "G":
output = 3
else:
if A1 == "U":
output = 4
else:
output = ""
I think the easiest solution would be to create a look up table and then use a combination of the INDEX MATCH functions to grab the appropriate value. You can read more about INDEX MATCH here: https://exceljet.net/index-and-match
To start, create a table similar to this:
Then assuming you have a list of letters you are trying to match you can write a formula similar to this: =INDEX(Table1[Output],MATCH(E3,Table1[Letter],0)). If you want the formula to return blanks "" instead of #N/A, you can wrap the formula in an IFERROR:
=IFERROR(
INDEX(Table1[Output],MATCH(E3,Table1[Letter],0))
,"")
Here's a picture of the final output.

Excel - Multiple Cell Calculation

I'm a teacher and trying to create a mark sheet the problem I have is that assignments are marked using different schemes (i.e. % [1 - 100], Level [1 -4], Letter Grade [F - A]). The problem I have is that I only want to report using one marking scheme and need to convert or calculate the other marking schemes based on the scheme there is it is marked.
I've made an excel worksheet which contains a student names and assignments. The sheet then has 3 other columns, one representing each scheme "Letter", "Level", Percentage a column for each scheme. Now, at any given time there is going to be a value in one of the 'scheme' columns - I need excel to automatically or by macro calculate the appropriate value into the other cells.
For example, there are three assignments each marked with a different scheme on the same sheet.
Assignment 1 - %
Assignment 2 - Level
Assignment 3 - Letter Grade
How can I get excel to check which mark value exists and then populate/calculate the other two the corresponding values.
Mike got 80% (%) on Assignment 1, but I want excel to populate the level column and letter column with the corresponding values at the same time Level 3 on Assignment 2 excel to calculate corresponding percentage and letter and at the same time for a Letter A on Assignment 3 the corresponding % and level should be calculated.
Don't know if this is possible or makes sense, but I tried VLOOKUP and was not successful because I have to do it all manually - I'm aiming for an automated process.
Sorry if it is not clear or confusing...but I've been at this for two days with no luck and not even sure if what I'm doing is possible.
of course it should be first assessed the translation of one rating system to the other and then assume those algorithms to shift between rating grades types
one of the possible approaches could be the following:
Option Explicit
Sub main()
Dim grades As Variant, levels As Variant
Dim cell As Range
Dim index As Double
grades = Array("F", "E", "D", "C", "B", "A")
levels = Array(1, 2, 3, 4)
For Each cell In Intersect(Range("A:C"), ActiveSheet.UsedRange).Offset(1).SpecialCells(xlCellTypeConstants)
Select Case cell.Column
Case 1 '%
index = cell.value / 100
cell.Offset(, 1).value = GetRate(index, levels)
cell.Offset(, 2).value = GetRate(index, grades)
Case 2 ' Level
index = InStr(Join(levels, ""), cell.value) / Len(Join(levels, ""))
cell.Offset(, -1).value = index * 100
cell.Offset(, 1).value = GetRate(index, grades)
Case 3
index = InStr(Join(grades, ""), cell.value) / Len(Join(grades, ""))
cell.Offset(, -2).value = index * 100
cell.Offset(, -1).value = GetRate(index, levels)
End Select
Next
End Sub
Function GetRate(index As Double, rates As Variant)
GetRate = rates(WorksheetFunction.Max(Round(index * (UBound(rates) - LBound(rates) + 1), 0) - 1, 0))
End Function
due to the simplicity of the translation algorithm it doesn't provide a bijective relationship between grading systems with different spans, but it can get you closer to your goal
Create a table like so (you can add more rows if you need to define +/- scores like "B+", etc.). The key here is sort the table ascending by %, with each row being the minimum score needed for the corresponding Level/Letter Grade.
Then, you can use VLOOKUP formula against this table, like so to get the Level:
=VLOOKUP(F2,$A$1:$C$7,2,TRUE)
And like so, to get the Letter Grade:
=VLOOKUP(F2,$A$1:$C$7,3,TRUE)
This takes advantage of the True parameter in the VLOOKUP function, which will return an approximate match (and assumes data is sorted ascending). So, when you enter a value like "81%", it returns the nearest row which is not greater than 81%, so it will return data from row 5. Likewise, 12% will return data from row 2, 75% from row 4, etc.
And your results:
You may need to use two tables if you can't 1:1 map the Level/Letter Grade to a Percent row, but the idea would be the same.

keeping a running sum of a formula with conditions

I am having an issue with an excel problem and cannot use vba or add any extra columns. The problem goes along with the format of this image. I could not find anything on google that helped me with this problem and im sorry if it has been asked before.
Example Image
On a separate page in a cell i need to write a function that will check if Info 2 = "z" and Info4 = "x" and if that is true then i need to do the following equation with the numbers in Info1 and Info3: Info1*(1 - Info3)
I will also have to keep a sum of these numbers.
For this example I would want the cell with the formula to equal -34 by doing the following:
3*(1-4)+5*(1-6) = -34
I would want the cell to just display the finished sum
Any help would be greatly appreciated,
Thank you!
You are looking for the mighty powers of SUMPRODUCT
=SUMPRODUCT((B:B="z")*(D:D="x")*(A:A)*(1-C:C))
The first two multipliers will make sure we only evaluate those rows having z for B and x for D. While the latter two are your desired function. Excel will evaluate this for each row and sum up the results.
I am using psuedo values below but this should work:
= [value of cell above] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
so basically starting in the middle, you have a two truth tests,
[info2] = "z", [info4]= "x"
using AND() requires they both pass
and([info2] = "z", [info4]= "x")
if they do pass you want to do your formula:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),FALSE)
but since we want to sum all values for each iterative row we make not passing this test 0:
if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
Ok so this works for one row, but doesn't sum the numbers from the tests on the previous row:
= [value of cell above or 0 for first row] + if(and([info2] = "z" , [info4] = "x"), [info1]*(1-[info3]),0)
an example written with real excel ranges that you may have to tweak depending on where your values are stored:
Sample picture

Resources