Find a certain sequence of numbers in a row of Excel data - excel

I am analysing some data in Excel where the results are shown in rows of cells, such as follows:
0 0 0 1 1 1 1 2 2 2 1 1
0 0 -1 -1 0 0 -1 -1 -2
(for both examples above lets say first cell is A1)
I am looking for help to find a formula can identify where a sequence in any row goes from either -1 to 0 or -1 to -2, and the result returns either a 1 for true and a 0 for false. Any help with this appreciated!

This will return false for the first example and true for the second. I am assuming your first example is in A1:L1 and your second is in A2:L2
=OR(AND(INDEX(A1:L1,,1)=-1, INDEX(A1:L1,,COUNT(A1:L1))=0), AND(INDEX(A1:L1,,MATCH(1, --(A1:L1<>0),0))=-1,INDEX(A1:L1,,COUNT(A1:L1))=-2))*1
This needs to be entered with Ctrl+Shift+Enter
However, I don't think your criteria is a logical test as logically both of these should fail (I'm assuming you've provided at least one example of your data that should pass)

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.

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.

Resources