calculate current consecutive streak ignoring blanks - excel

I have a daily log with four different value types. Positive, Negative, Zero, or Blank.
I am interested in the consecutive Zeroes, where Positive and Negative values end the streak, and Blanks are ignored.
Each record is on 1 row and contains a name and values
Example:
Day 1 2 3 4 5 6 7 8
Fred 1 -2 0 _ 0 0 0 0 calculate current streak of 5
Jane 0 -5 _ 0 0 _ _ _ calculate current streak of 2
John 4 -6 3 0 0 0 3 0 calculate current streak of 1
Amie 2 0 0 0 0 0 0 -3 current streak 0
I can use COUNTIF to get the total zeroes, but not the streak
From this similar question, calculate consecute streak in excel row
I've tried variations of =IFERROR(MATCH(TRUE,INDEX(B2:I2<>0,0),0)-1,COUNT(B2:I2))
I'm getting wonky results, and my supervisor wants me to be done with this already. Any help or ideas would be greatly appreciated!

Formula in K2:
=IFERROR(SUM(INDEX((COLUMN(B2:I2)>LOOKUP(2,1/((B2:I2<>0)*(B2:I2<>"")),COLUMN(B2:I2)))*(B2:I2=0)*(B2:I2<>""),)),COUNTIF(B2:I2,0))
Drag down..
There probably is a neater way.

Related

Counting the number of instances a row changes from a specific number to another

Got a bit of a conundrum I've been wracking my brain on for far to long and was wondering if anyone could help.
I have a list of items in column A and columns labelled as weekly periods from B:DA
Item Code
Week 1
Week 2
Week 3
Week 4
Week 5
Week 6
Week 7
Week 8
Results
Item 1
1
1
0
1
0
0
1
0
3
Item 2
1
1
0
0
1
1
1
I need to count the number of times the weekly status goes from 1 to 0 but not from 0 to 1.
In the tabled example I would expect the results to be Item 1 = 3 and Item 2 = 1
Any help pointing me in the right direction would be much appreciated!
Use COUNTIFS():
=COUNTIFS(B2:CZ2,1,C2:DA2,0)
The offset ranges will allow the count of when the prior cell is 1 and the following is 0.

Pandas in Python 3 - Return list of highest sum

I want to find the sum of each column in the dataframe below and return a list of the highest sums. I've tried to use the code below however it only reports the max number. How do I update to include the column label (or labels if there are multiple columns if more than one column equals the max).
grouped = df.sum()
mostPurchased = grouped.max()
print(grouped)
snow suit
gloves
coat
boots
january
1
0
0
0
february
1
0
1
0
march
0
0
0
0
april
0
0
1
0
may
0
0
1
1
june
0
0
0
1
july
0
1
0
1
I want this to return:
Coat 3, Boots 3
Select the columns where the column sum equals the max column sum:
grouped = df.sum()
grouped[grouped == grouped.max()]
#coat 3
#boots 3
#dtype: int64

Google Sheets – countifs across rows

I have a schedule that my team fills out daily in a google sheet. On a seperate tab, I would like a running count per day per schedule code per agent.
Linking a sample spreadsheet here. In this example, I'm trying to input a countif that returns
2019-01-27 T 5 6 0 4
2019-01-27 C 3.5 0 0 7
2019-01-27 LC 0 0 0 0
2019-01-27 S 0 0 0 0
2019-01-27 L 0.5 0 0 1
2019-01-27 M 0.5 0 0 1
2019-01-27 SP 0 0 0 0
2019-01-27 U 0 0 0 0
2019-01-27 MCX 2 0 0 2
2019-01-27 OCX 0 0 0 0
2019-01-27 TR 0 0 0 0
But I cannot for the life of me get a countifs function to work. Any help is much appreciated!
https://docs.google.com/spreadsheets/d/1gp0ZrcYLJfEnUHxgxagAl99X_MCjEIdvwFyfSdGngSE/edit?usp=sharing
Combine INDIRECT with MATCH:
=COUNTIF(INDIRECT("'Mon 1/27'!F"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)&":AG"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)),$B2)
INDIRECT
MATCH
Here is how it works:
MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0) will search the row number of the agent, referenced to cell A1
INDIRECT("'Mon 1/27'!A"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)&":AG"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)) will return a range referenced always to columns F and AF but with the row number returned in step 1, ie, F3:AG3,F4:AG4, and son.
COUNTIF will just count the criteria in the range from step 2.
Hope this helps.
IMPORTANT: In the expected output you posted, the MCX result for Barack Obama is 2, but my formula gets 4. Are you sure your output is right?

Excel multiple search/match and sum (edit: answered with SUMIFS, COUNTIFS)

I am looking for help to solve this excel problem.
Essentially I want to create a formula for cells in column F which does a multiple search on 3 criteria (on cells in columns A,B,C) and want to access the corresponding column D values where all these (multiple) matches occur, and sum this in column F. I'd also like a count of the amount of matches found to calculate the value in column F; placed alongside in column G.
e.g.
IF col_A_value (anywhere in whole A column) = current_col_A_value +/- 1
AND col_B_value (anywhere in whole B column) = current_col_B_value +/- 1
AND col_C_value (anywhere in whole C column) = current_col_C_value - 1
THEN (output in column F) the sum of all values from row D where this criteria is met
(also, as a seperate but related cell formula, output in column G) the total Count of times this occurs.
Note: the values in columns A,B,C are all integars and the +/- above means to search for any values which are either +1, 0, or -1 different in value. (i.e. this includes the value itself).
e.g. If the value in cell A1 = 10, B1 = 45, C1 = 881, then the first search criteria would look for all other rows with values of 9, 10 or 11 in column A. Then based on these rows, the second search criteria would refine the search to only those rows which also include either a 44, 45 or 46 in column B, and the third search criteria would refine the search again to only include those rows where the column C value is 880.
Next, the values in the column D cells from all of these 'filtered' rows would be summed and the result placed in the column F cell. (The count of these results rows would be put in column G. (seperate formula required))
Since these are all unique entries (think of columns A,B,C creating unique vector coordinates in space), there should be a maximum of 9 entries found and summed. A +/-1: 3 variations, B +/-1: 3 variations and C -1 only: 1 variation. In total: 3x3x1 = 9 unique rows maximum (and potentially none as a minimum, as in the below example).
(If no match is found a value of 0 is good.)
Example with A,B,C,D and E as given values, and column F values calculated (together with the count shown in col G):
A B C D E F G
1 1 1 90 8 0 0
1 2 1 80 6 0 0
1 3 1 70 1 0 0
1 4 1 60 6 0 0
2 1 1 50 1 0 0
2 2 1 40 8 0 0
2 3 1 30 6 0 0
2 4 1 20 8 0 0
3 1 1 10 8 0 0
3 2 1 11 6 0 0
3 3 1 12 1 0 0
3 4 1 13 1 0 0
1 1 2 99 8 260 4
1 2 2 89 6 360 6
1 3 2 79 1 300 6
1 4 2 69 6 180 4
2 1 2 59 1 281 6
2 2 2 49 8 393 9
etc
To illustrate how column F values are calculated here is the working:
260 = 90+80+50+40
360 = 90+80+70+50+40+30
300 = 80+70+60+40+30+20
180 = 70+60+30+20
281 = 90+80+50+40+10+11
393 = 90+80+70+50+40+30+10+11+12
Thanks a lot for any help with this!
These formulas should do what you desire:
F1: =SUMIFS(D:D,A:A,"<="&A1+1,A:A,">="&A1-1,B:B,"<="&B1+1,B:B,">="&B1-1,C:C,C1-1)
G1: =COUNTIFS(A:A,"<="&A1+1,A:A,">="&A1-1,B:B,"<="&B1+1,B:B,">="&B1-1,C:C,C1-1)
The formulas can simply be copied down as you need them...
(Still I don't know what col E is for)

Count values in a range comprehended between two values

At Column A i have this values 1
0
3
2
0
5
1
1
1
0
2
1
1
1
0
2
1
1
1
0
0
3
0
2
0
0
3
1
This list grows everyday.
I need a formula to put on every cell of column B that counts upwards how many values bigger than 1 are until the next value = 1 is found.
In another words i need to count how many values larger than 1 are between 1's.
The pretended result would be something like this:
1
0
3
2
0
5
1 3
1
0
2
1 1
1
0
2
1 1
1
0
0
3
0
2
0
0
3
1 3
Thanks in Advance
I would use a helper column, if this is acceptable.
So to create a running count of numbers greater than one which resets each time it encounters a '1', enter this starting in B2 and pull down (I'm assuming the data has a heading and the list starts with a 1) :-
=IF(A2=1,0,B1+(A2>1))
Then to display the counts at each '1' value (but not for repeated ones) enter this in C2 and pull down:-
=IF(AND(A2=1,A1<>1,ISNUMBER(A1)),B1,"")
It's also possible to do it with an array formula, but not sure if it's worth the effort:-
=IF(AND(A2=1,A1<>1),
COUNTIF(
OFFSET(
A$1,
MAX(ROW(A1:A$2)*(A1:A$2=1))-ROW(A$1)+1,,
MAX(ROW(A1))-MAX(ROW(A1:A$2)*(A1:A$2=1))),
">"&0),
"")
to be entered in B2 with Ctrl Shift Enter and pulled down.

Resources