Counting digit in column based on subject - excel

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.

Related

excel to find first value within column that match criteria

For the same Project_Id if the first cell (in ‘Success’) is 1, than make all ‘output’ cells for that matching project_id a 1….
And for the same Project_Id if the first cell (in ‘Success’) is 0, than make all ‘output’ cells for that matching project_id a 0….
I had previous used:
IF((COUNTIFS($A:$1:A1,A1,$B$1:B1,0)),0,1)
However this is not correct as it does the following: if there are ANY 0’s in the range, than make it 0.
i have also tried this: =IF(MIN(IF($A$2:$A$9=A2,$B$2:$B$9))=1,1,0)
however it does not work properly particularly in cases where it should give a 1... not a 0...
Would appreciate some help!!
column A
column B
column C
Project_Id
Success
output
1
1
1
1
0
1
1
0
1
2
0
0
2
1
0
2
1
0
2
1
0
2
1
0
2
1
0
Since all values would be available, alternatively use VLOOKUP():
Formula in C2:
=VLOOKUP(A2:A10,A2:B10,2,0)
XLOOKUP() can give you desired output. Try-
=MAP(A2:A10,LAMBDA(x,XLOOKUP(x,A2:A10,B2:B10,"",0,1)))
Single XLOOKUP() will also work, like-
=XLOOKUP(A2:A10,A2:A10,B2:B10,"",0,1)
To make input argument dynamic can use A2:INDEX(A2:A50000,COUNTA(A2:A50000)). Try-
=XLOOKUP(A2:INDEX(A2:A50000,COUNTA(A2:A50000)),A2:A10,B2:B10,"",0,1)
I have used MAP() for dynamic spill results.

How to find a specific data of consecutive numbers inside an excel spreadsheet column

Please help me to find sequence of numbers present in column of a spreadsheet.
I have a large data of 1's and 0's in an excel column, I need to find the sequence of consecutive 1's and 0's in the column. For example, my excel column is given below:
0
0
1
1
0
0
1
0
1
0
0
1
1
0
1
1
1
0
0
Please assume this as some of my column data, I need to find where are the sequences of 1's and 0's present in the column.
For example, I need to find:
0
0
1
1
0
1
This sequence of data in the column.
Is there any function for sequence search or something? Please Help!!
In Excel 2019 and O365, it's rather easy using CONCAT():
=FIND("001101",CONCAT(A1:A19))
However, combining a range of cells prior to these versions of Excel can be tricky. You will quickly get tangled up in syntax like =MAX((A1:A19=0)*(A2:A20=0)*(A3:A21=1)*(A4:A22=1)*(A5:A23=0)*(A6:A24=1)*(ROW(A1:A19))) (as an array formula). An UDF is not a bad alternative in this case:
Function FINDSEQ(seq As String, rng as Range) As Long
FINDSEQ = InStr(1, Join(Application.Transpose(rng.Value), ""), seq)
End Function
Call like: =FINDSEQ("001101",A1:A19)
Note - Better solutions may be found since Application.Transpose will have an upperbound limit.
If the numbers are formated as string you can simply do: =search("1 1 0 1 0 1";A1)

excel extendable formula for conditional sums over multiple columns

I have an arbitrary number of columns, one for each period a course is offered, in chronological order, and an arbitrary number of rows, one for each unique participant. The values are '1' for participation in that month, '0' for non-participation.
Fall2019 Spring2019 Fall2018 Spring2018 Fall2017
1 1 0 1 0
0 1 1 1 1
0 1 1 1 1
0 1 1 1 1
0 1 0 1 1
0 1 1 0 0
0 1 1 0 0
0 1 1 0 0
1 0 0 0 0
I would like to take a sum, at the bottom of each column, for how many participants were first time attendees that period, i.e. the sum of '1's where all values in the row to the right of that '1', are '0'.
In the given example set, Spring2018 should sum to 1, Fall2018 should sum to 3.
Something like the formula below will work for 'Spring2018' when there is just one previous column to compare:
=SUMPRODUCT((D2:D9)*(E2:E9=0))
But this formula cannot be 'autofilled' or extended across multiple columns... i.e. none of these variations work:
=SUMPRODUCT((C2:C9)*(D2:$E9=0))
=SUMPRODUCT((C2:C9)*(SUM(D2:$E9)=0))
=SUMPRODUCT((C2:C9)*(SUMIF(D2:$E9,"0")))
And while it will work, I do NOT want to have to manually create extended versions of this formula e.g.
=SUMPRODUCT((C2:C9)*(D2:D9+E2:E9=0))
=SUMPRODUCT((B2:B9)*(C2:C9+D2:D9+E2:E9=0))
... and so on
I have tried several variations on arrayformula, sumproduct, and sumif, but I'm really stuck. Any assistance is appreciated.
use this array formula:
=SUM(A2:A10*(MMULT(--(B$2:$E$10=1),TRANSPOSE(COLUMN(B$2:$E$10)^0))=0))
Being an array formula it must be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Count of consecutive repeated value only when repeated 3+ times

My goal is to count and potentially conditionally format the occurrences when a certain number of days pass with 0 sales.
I am trying to return the number of times 0 is repeated consecutively 3 or more times. So for this example I would like to see the return value of 3. So far I can't wrap my brain around how to do this, any ideas?
1
5
0
0
0
0
0
2
0
0
1
0
2
0
0
0
5
0
0
0
0
Thanks!
So #Barry Houdini's method applied to this problem would give
=SUM(--(FREQUENCY(IF(A1:A21=0,ROW(A1:1A21)),IF(A1:A21>0,ROW(A1:A21)))>=3))
entered as an array formula using CtrlShiftEnter
If you wanted to make it more dynamic and exclude blanks you could use
=SUM(--(FREQUENCY(IF(A1:A100<>"",IF(A1:A100=0,ROW(A1:A100))),IF(A1:A100>0,ROW(A1:A100)))>=3))
How about you make a help column with a simple sum formula with a "window" of three rows (or whatever you need). Then you conditionally format all values which are 0 in that column. That should provide you with the information you are looking for.

How to treat two same value as 1 and add with other value in excel

I have datasets which contains same value, please find the below datasets,
`
A B
1122513454 0
1122513460 0
1600041729 0
2100002632 147905
2840007103 0
2840064133 138142
3190300079 138040
3190301011 138120
3680024411 0
4000000263 4000000263
4100002263 4100002268
4880004352 138159
4880015611 138159
4900007044 0
7084781116 142967
7124925306 0
7225002523 7225001325
23012600000 0
80880593057 0
98880000045 0
`
I have two columns ( A & B).Into the b column i have same value (138159,138159).It appears two times.
I just want to build a formula, where it will get a same value it will count as 1. That means, i am getting two 138159, but formula will treat as 1. and finally it will count the whole b column value.
That means,
0 is here 10 times and other value is also 10 times, but 138519 appears 2 times, so it will counted as 1, so other values are 9 times.
So my expected output will be 10+9=19
I have written following formula for that
=+COUNTIF(K20:K39,0)+9
I did manually. and it's driving me crazy.
can you guys help me for that.
any suggestion is really appreciable.
Try,
=SUMPRODUCT((B1:B20<>0)/COUNTIFS(B1:B20, B1:B20))

Resources