3 condition formula in excel - excel-formula

I need these conditions:
If b<=0, a>=0 = a/2
if b<=0, a<=0 = 0
if b<=0 = 0
I use these 2 formulas:
=IF(E1<=0,D1/2,IF(E1>=0,"",IF(D1<=0,"")))
=IF(E1<=0&D1>=0,D1/2,0),elseif(E1<=0&D1<=0,0),IFelse(E1>=0,0)
But when b<=0, a<=0 is not working. Ex.- if both b and a cells are negative or <=0 it is not working. Is it possible for those 3 conditions apply?
I have tried these formulas, but none of them work correctly when no2 condition:
=IF($E$30<=0,$D$26/2,IF($E$30>=0,"",IF(D26<=0,"")))
=IF(E30<=0&D26>=0,D26/2,0),elseif(E30<=0&D26<=0,0),elseif(E30>=0,0)
=IF(E30<=0,D26/2,IF(AND(D26>=0,E30<=0),D26/2,0))
=IF(E30<=0&D26<=0,0),IF(E30<=0&D26>=0,D26/2)

This by chance what you are after:
=IF(AND(B1<=0,A1>=0),A1/2,IF(AND(B1<=0,A1<=0),0,IF(B1<=0,0,"")))

Related

Counting digit in column based on subject

I am just using formulas in excel and was wondering how you could count all the 0s until a 1 is reached, and then start the process over again, based on subject number. If this is not possible simply with formulas, how could I write a VBA code for this?
Right now I am trying to use,
=IF(OR(F4=0,F3=1),"",COUNTIFS($A$2:A2, $A$2,$F$2:F2,0)-SUM($I$2:I2))
which I input in I3 and I change the COUNTIFS($A$#:A#, $A$#...) part for each subject number.
This seems to work with the exception of the last grouping, as it won't output a number before the next subject.
Example Data:
subid yes number_yes(output)
1 0
1 0
1 0 3
1 1
1 0 1
1 1
1 0
2 0
2 0 2
2 1
2 0
2 0
3
etc.
A blank cell is numerically zero and that is one of your accepted conditions. Differentiate between blanks and zero values.
=IF(and(f4<>"", OR(F4=0,F3=1)),"",COUNTIFS($A$2:A2, $A$2,$F$2:F2,0)-SUM($I$2:I2))
Based on #Jeeped answer. If you use -SUMIF($A$2:A2,A3,$I$2:I2) instead of -SUM($I$2:I2) you don't need to adjust this part for each subject number. Just use the following formula in I3 and copy it down.
=IF(AND(F4<>"",OR(F4=0,F3=1)),"",COUNTIFS($A$2:A3,A3,$F$2:F3,0)-SUMIF($A$2:A2,A3,$I$2:I2))
Note that I also changed the second parameter in the COUNTIFS to A3.

3 Outcomes to a formula

I'm a newbie on here and I'm struggling to do a formula on Excel,
I basically need If;
F7= Int 0 then J7=Int 1
or
F7=Rus 0 The J7=Rus 1
or
F7=Red 0 then J7=Red 1
F7 has data validation so I can choose from either Int 0 / Rus 0 / Red 0 and I need J7 to follow suit with either Int 1 /Rus 1 /Red 1 depending on what F7 is.
This all seemed so easy to explain in my head lol so I apologize
I can do it when there are 2 outcomes ie a true or false but because there are 3 I'm struggling.
How about this:
=LEFT(F7, 4) & MID(F7, 4, 100)+1
Based on your last sentence about 3 if() statements, try this:
=IF(Test1,result1,IF(Test2,result2,result3))

How to count the values in ranges in Excel

I have two columns as shown below. Group values is 0,1,2,3,4 and scores is from 0 to 80. I want to count how many 0s (1s, 2s, 3s, 4s) are present for scores between 0 and 10; 10 and 20; 20 and 30 etc.
I am thinking to use Excel pivot table. But I am stuck - how could I achieve this?
Group scores
1 8.56163
2 34.3649
2 12.2291
0 8.75357
2 8.75967
2 5.87806
0 9.33751
2 32.0303
0 43.5567
2 11.1044
2 24.9266
1 18.9314
-------- result should look like below --------
scores group count
0-10 0 2
0-10 1 1
0-10 2 2
0-10 3 0
0-10 4 0
10-20 0 0
10-20 1 1
10-20 2 2
...
------ PS I have solved this problem using matlab. But it would be nice to see someone do it in Excel.
---------------- thanks for all the anwers. I really appreciate it. I have accepted the 1st answer.
I apologize for my previous answer. You can do binning with PivotTable.
select your whole two columns (A1:B13), insert PivotTable
under rows, put your "Group"
under columns, put your "scores"
under values, put your "Group"
click that last one ("Group" within the values quadrant) and change it to count, not sum
intermediate result:
Now in the resulting pivot table, right click on a colum and select "Group and show detail". You can configure your bins there.
Result:
One option is to use a pivot table, but another option is to use COUNTIFS, e.g.:
=COUNTIFS($A$2:$A$13,"="&$F2,$B$2:$B$13,">="&D2,$B$2:$B$13,"<="&E2)
In practice:
You could just use simple countif formulas:
Type out first criteria into cells. D1 = 0, E1 = 1, F1 = 2 etc.
Now you can just say =COUNTIF($A$2:$A$13,D1) and just drag that out.
The other column would require countifs.
Lets say D3 is blank E3 = ">10", F3 = ">20", etc.
Now D4 = "<=10", E4 = "<=20", F4 = "<=30", etc.
Now you can use =COUNTIF($B$2:$B$13,D4) for your first criteria and =COUNTIFS($B$2:$B$13,E4,$B$2:$B$13,E3) for the next criteria and just drag that out.
Hope this helps, good luck!
Please try:
This uses Grouping (by decade) for the Row labels.
To Group, right-click on one of the entries under Row Labels and Group..., then select enter Starting at:, Ending at: and By: to suit:

Finding the first specific value above a certain cell

I'm looking for a way to find the first specific value above a certain cell.
Using the example below, in the result column every time I hit a A in COL2, I need to substract the value in COL1 to the first A value above.
The trouble seems finding a way to keep the range dynamic...
I thought of =IF(B5="A";A5-INDIRECT("A"&MATCH("A";B:B;0));"")
But of course that only works for the first one as Match will always pick up the first one.
Any ideas? Thanks!
Example :
COL1 COL2 Result
1 A
2 0
3 0
4 A 4 - 1 = 3
5 0
6 A 6 - 4 = 2
7 0
8 0
9 0
10 A 10 - 6 = 4
Try this:
=IF(AND(ROW(B2)<>2,B2="A"),A2-INDEX($A$1:$A1,AGGREGATE(14,6,ROW($1:1)/($B$1:$B1="A"),1)),"")
The AGGREGATE() Function was introduced in 2010.
In D2 enter =IF(B2="A",A2-INDIRECT("A"&MATCH("A"&(E2-1),F:F,0)),"")
In E2 enter =IF(B2="a",COUNTIFS($B$2:B2,"a"),"")
In F2 enter =B2&E2
Copy formulas from D, E and F down all your rows
Column D is the result you're looking for

Excel - Adding up numbers until cetain condition found

I probable have a simple question if you know the answer to it, but I'm kind off stuck myself and I wasn't able to find anything about it on the internet.
So, I have a excel sheet like the following:
Stop? Number
0 2
0 5
1 7
0 3
1 0
0 12
0 1
0 1
1 4
Totals
1st 14 (2+5+7)
2nd 3 (3+0)
3th 18 (12+1+1+4)
As you may already have noticed, I need to count the numbers in the Number colum until I find a 1 in the Stop colum, and save those within the 'fist'/'2nd'/'3th'/etc..
I have tried a lot of other solutions and own ideas but nothing lead to the correct answer.
I hope someone can help me,
Thanks,
Merijn
You can use a helper column and SUMPRODUCT. With reference to the figure, the important formulas are:
C2: =1
C3: =C2+A2 (copy downwards).
F2: =SUMPRODUCT(($B$2:$B$10)*($C$2:$C$10=E2)) (copy downwards).
You could use 4 columns :
A(stop) B(cumulated stop) C(number) D(cumulated number)
0           0                             2                2
0           0                             5                7
1           1                             7                14
0           1                             3                3
1           2                             0                3
0           2                             12              12
0           2                             1                13
0           2                             1                14
1           3                             4                18
B :
B(1) = A(1)
B(N) = B(N-1) + A(N)
D :
D(1) = C(1)
D(N) = IF(A(N-1)=1,C(N),D(N-1)+C(N))
1st :
INDEX($D$1:$D$9, MATCH(1,$B$1:$B$9, 0))
2nd :
INDEX($D$1:$D$9, MATCH(2,$B$1:$B$9, 0))
3rd :
INDEX($D$1:$D$9, MATCH(3,$B$1:$B$9, 0))
Hope this helps !

Resources