calculate consecute streak in excel row - excel

I am trying to calculate 2 values. Current Streak and Long Streak.
each record is on 1 row and contains a name and values
each of those columns has a value from 1 to 200.
Example:
John Doe 14 16 25 18 40 65 101 85 14 19 18 9 3
Jane Doe 24 22 18 5 8 22 17 17 15 2 1 5 22
Jim Doe 40 72 66 29 25 28
Jan Doe 27 82 22 17 18 9 6 7 9 13
For each row, I'm trying to find the "current" streak and "longest" streak.
The values have to be <= 24 to be counted. Data goes left to right.
John: Current 2; Long 5
Jane: Current 13; Long 13
Jim: Current 0; Long 0
Jan: Current 0; Long 8
What would be a formula to calculate the current and long in their own cell on that same row (would have to go before data)?

For current run, assuming data in C2:Z2, try this array formula:
=IFERROR(MATCH(TRUE,C2:Z2>24,0)-1,COUNT(C2:Z2))
Confirm with CTRL+SHIFT+ENTER
For longest streak try this version based on the cell references used in your comment
=MAX(FREQUENCY(IF(P7:BB7<=24,COLUMN(P7:BB7)),IF(P7:BB7>24,COLUMN(P7:B‌​B7))))
Again confirm with CTRL+SHIFT+ENTER
or to allow blanks in the range (which would end a streak) you can use this version
=MAX(FREQUENCY(IF(P7:BB7<>"",IF(P7:BB7<=24,COLUMN(P7:BB7))),IF((P7:BB7="")+(P7:BB7>24),COLUMN(P7:BB7))))

Related

Counting combinations of values in table of values excel?

I have a table of values with each value in a different cell
e.g.
2 9 12 19 41 45 14 39
12 14 19 27 39 40 30 44
6 9 13 15 16 41 7 20
8 16 14 34 13 44 5 15
10 11 20 24 27 36 9 41
Is there a way to find which pairs of numbers are most common.
i.e.
13 & 15 appear 2 times
14 & 44 appear 2 times
24 & 27 appear 1 time
I was hoping for a formula as the table has over a hundred rows in it so would be time consuming to count manually.
The formula you would want would be the one for the row totals of a pair of numbers in A2 and B2:
=SUM(MMULT(--($E$2:$L$6=A2),TRANSPOSE(COLUMN(E:L))^0)*MMULT(--($E$2:$L$6=B2),TRANSPOSE(COLUMN(E:L))^0))
entered as an array formula using CtrlShiftEnter
There will be formulas for for listing distinct pairs up to a certain number out there - I used
=IF(ROW()=2,1,IF(B1<45,A1,A1+1))
for A2 and
=IF(B1<45,B1+1,2+COUNTIF(B$1:B1,45))
for B2.
If you scroll down this list you can see that 13,16 occurs twice as well as 13,15.
9,41 occurs three times.
Note - I am assuming the numbers are like lottery numbers and any one number can only occur once in a row. The formula could easily be modified to account for duplicates within a row.

Excel: Subtracting One Value from the Next Entry in Column

I have a set of data that has two columns, one for enumerating entries, and the second for storing a value:
1 0.000000000
2
3
4
5
6
7
8
9 0.664076596
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 0.668394223
The values in column 2 are separated by varying numbers of rows throughout my data sheet. I want to subtract each value (Value B) in column 2 by the previous value above it (Value A) (ie 0.664076596 - 0.000000000, and 0.668394223 - 0.664076596 etc.). I want to put these results in the third column and next to Value B. How would I do this in Excel?
Use this which will find the last number value in the column before the current row.
=IF(B2="","",IFERROR(B2-INDEX($B$1:B1,MATCH(1E+99,$B$1:B1)),B2))

find the number of skip rows between records

I have requirement to get row number of next matching value. ie.
Number 1 Number 2 Number 3 Number 4 Number 5 Number 6
16 33 28 20 23 14
13 12 27 29 2 32
31 25 9 28 17 10
11 22 14 3 18 13
12 39 22 32 25 24
37 40 33 18 9 3
4 35 17 24 7 12
16 3 38 8 17 24
now 16 is present in 7th row, and skipped rows are 6. 33 is present in 6th row so skipped rows are 5. Similarly 28 is present in 3rd row so skipped rows are 1.
output will be :
6 4 1 19 10 2
assume that 20 and 23 found in 20th and 11th row respectively.Skipped rows = row number of next find of that number - present row number.
I am not able to form formula for this. Match should work I guess, but not sure.
Put this formula in the first cell:
=AGGREGATE(15,6,ROW($A$3:$F$22)/($A$3:$F$22=A2),1) - ROW($A$3)
Then drag/copy across
If you want to drag down (put the results in columnar form):
=AGGREGATE(15,6,ROW($A$3:$F$22)/($A$3:$F$22=INDEX($2:$2,ROW(1:1))),1) - ROW($A$3)
Put it in the first cell and drag/copy down.

how can I define sequence of used ID?

I have ProductID:
ProductID
12
85
14
14
14
17
65
65
I need to create a new column where i could count how many times i have the same ProductID. I mean:
ProductID Count
12 1
85 1
14 1
14 2
14 3
17 1
65 1
65 2
The formula I currently have is = IF((A3=A2),F2+1,1), but it doesn't work.
Use this formula if you want the count of each individual entry to be same. (i.e count for 14 will be 3 as it exists three times in the data set)
=COUNTIF($A$2:A9,A2)
Output is attached for your reference.
In B2 enter:
=COUNTIF($A$1:A2,A2)
and copy down

Excel SUMIF based on array using text string

Is there a way to substitute the cell address containing a text string as the array criteria in the following formula?
=SUM(SUMIF(A5:A10,{1,22,3},E5:E10))
So instead of {1,22,3}, "1, 22, 3" is entered in cell A2 the formula becomes
=SUM(SUMIF(A5:A10,A2,E5:E10))
I have tried but get 0 as a result (refer C16)
A B C D E F G H
1 Tree
2 {1,22,3} 1
3 22
4 Tree Profit 3
5 1 105
6 2 96
7 1 105
8 1 75
9 2 76.8
10 1 45
11
12 330 =SUM(SUMIF(A5:A10,{1,22,3},B5:B10))
13
14 330 =SUMPRODUCT(SUMIF(A5:A10,E2:E3,B5:B10))
15
16 0 =SUM(SUMIF(A5:A10,A2,B5:B10))
17 NB: Custom Format "{"#"}" on Cell A2 I enter 1,22,3 so it displays {1,22,3}
Ok so after some further searching (see Excel string to criteria) and trial and error I have come up with the following solution.
Using Name Manager I created UDF called GetList which Refers to:
=EVALUATE(Sheet1!$A$3) NB: Cell A3 has this formula in it =TEXT(A2,"{#}")
I then used the following formula:
=SUMPRODUCT(SUMIF($A$5:$A$12,GetList,$B$5:$B$12))
which gives the desired result of 321 as per the other two formulas (see D12 below).
If anyone can suggest a better solution then feel free to do so.
Thanks to Dennis to my original post regarding table
A B C D E
1 Tree
2 1,22,3 1
3 {1,22,3} =TEXT(A2,"{#}") 22
4 Tree Profit 3
5 11 105
6 22 96
7 1 105
8 3 75
9 2 76.8
10 1 45
11
12 321 =SUMPRODUCT(SUMIF($A$5:$A$12,GetList,$B$5:$B$12))
13
14 321 =SUM(SUMIF(A5:A10,{1,22,3},B5:B10))
15
16 321 =SUMPRODUCT(SUMIF(A5:A10,E2:E3,B5:B10))
17
18 0 =SUM(SUMIF(A5:A10,A2,B5:B10))
19 NB: Custom Format "{"#"}" on Cell A2 I enter 1,22,3 so it displays {1,22,3}

Resources