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 !
Related
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.
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))
I'm new to array formulas in Excel and my brain has been trained in R for too long, so I'm sorry if this question is simple or too specific. I have data that looks like this:
ID Iteration Value Group1 Group2
2 1 100 0 0
2 2 85 1 0
2 3 28 0 0
3 1 94 1 0
5 1 83 0 1
5 2 50 1 1
6 1 94 0 0
6 2 28 1 0
I want to use array formulas to query the data in a few different ways. I want to:
For each ID, find the first iteration that has Group1 = 1.
For each ID, what is the maximum value when Group1 = 1.
For each ID, how many iterations of Group1 = 1 did it take to get to the maximum value when Group1 = 1.
I've figured out how to specify the maximum for each ID via: {=MAX(IF(A:A=A2,C:C))}
Any assistance would be appreciated. I've gone through a few quick tutorials so far, and I'm willing to look through any other good resources you may know of.
Have a look at this and tell me what you think - particularly for question 3
My setup looks like this
All formulas drag down and they are as follows:
Formula in B14 (Question 1)
{=INDEX($B$2:$B$9,MATCH(1,($A$2:$A$9=A14)*($D$2:$D$9=1),0))}
Formula in G14 (Question 2)
{=MAX(($A$2:$A$9=$F14)*($D$2:$D$9=1)*$C$2:$C$9)}
Formula in K14 (Question 3)
{=SUM(($A$2:$A$9=J14)*($C$2:$C$9=G14)*$B$2:$B$9)}
Update
If you want to know how many times in ID=2 that Group1=1 before we reach the maximum we found for ID =2 in question 2, then I'd proceed like this:
Add another column to your data, I labeled it: Group1 Passes. Placing this in the new column, F2, and drag down.
=COUNTIFS($A$2:A2,A2,$D$2:D2,1)
You can then use the following in K14
=SUM(($A$2:$A$9=J14)*($C$2:$C$9=G14)*($D$2:$D$9=1)*$F$2:$F$9)
I want to find a way for Excel to automatically give me the following 'interval':
Month 1 2 3 4 5 6
Demand 1 0 0 1 0 1
'Interval' 0 0 0 3 0 2
The 'interval' shows the amount of months between the demands. Is this doable in some sort of way? I couldnt find a function in Excel to do this. Maybe there is a way in VBA? I need this for the CROSTON forecasting method.
Thank you in advance for your time and effort!
J. Rommers
Count the number of consecutive zeros in the row above and adjust. In B3 enter:
=IF(B2=0,0,COUNTIF($B$2:B2,"=0")-SUM($A$3:A3))
and copy across:
Assuming the 3 columns are A, B and C use:
=MATCH(1,Bn:B1,0)-1
where Bn its the n of C
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