Columns- count a consecutive series of positive or negative numbers and then get a sum of the max frequency

mr_king

New Member
Joined
May 18, 2018
Messages
15
[FONT=&quot]Columns- count a consecutive series of positive or negative numbers and then get a sum of the max frequency [/FONT]
[FONT=&quot]
Example:
ABCDEFGHIJKLM
-1-2-313580-1-3-1-1-4

<tbody style="box-sizing: inherit; border: 0px; margin: 0px; padding: 0px; vertical-align: top; -webkit-font-smoothing: antialiased; text-size-adjust: none;">
</tbody>
max positive count is 4 and the sum is 17.
max negative count is 5 and the sum is -10
Looking for excel array formula please for Microsoft office 2016.
Thanks!
[/FONT]
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I have figured out how to get the streaks, but I can't seem to get the sum of the streaks. I'll keep working on it, so stay tuned.....


Book1
AB
3longest streak
4positives4
5negatives5
Sheet69
Cell Formulas
RangeFormula
B4{=MAX(FREQUENCY(IF(A1:M1>0,COLUMN(A1:M1)),IF(A1:M1<=0,COLUMN(A1:M1))))}
B5{=MAX(FREQUENCY(IF(A1:M1<0,COLUMN(A1:M1)),IF(A1:M1>=0,COLUMN(A1:M1))))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
The rather painful formulas in C4:C5 will calculate the sum of the longest streaks, given the formulas that DRSteele provided. It might be possible to simplify them, but probably not by much. I'd recommend you update the macro in your other thread to perform this calculation too.


ABCDEFGHIJKLM
11-2-313580-1-3-1-1-4
2
3longest streakSum of longest streak
4positives417
5negatives5-10

<tbody>
</tbody>
Sheet14

Array Formulas
CellFormula
B4{=MAX(FREQUENCY(IF(A1:M1>0,COLUMN(A1:M1)),IF(A1:M1<=0,COLUMN(A1:M1))))}
C4{=SUM(OFFSET(A1,0,MATCH(B4,MMULT(--(A1:M1>0),TRANSPOSE(IF((COLUMN(A1:M1)>=TRANSPOSE(COLUMN(A1:M1)))*(COLUMN(A1:M1)<=TRANSPOSE(COLUMN(A1:M1))+B4-1),1,0))),0)-1,1,B4))}
B5{=MAX(FREQUENCY(IF(A1:M1<0,COLUMN(A1:M1)),IF(A1:M1>=0,COLUMN(A1:M1))))}
C5{=SUM(OFFSET(A1,0,MATCH(<fo
B5,MMULT(--(A1:M1<0),TRANSPOSE(IF((COLUMN(A1:M1)>=TRANSPOSE(COLUMN(A1:M1)))*(COLUMN(A1:M1)<=TRANSPOSE(COLUMN(A1:M1))+B5-1),1,0))),0</fo
)-1,1,B5
))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0
There is a conceptual problem: you might have several sets of longest streaks (of say 4), but they will sum to different values. Should then the largest of the sums of the longest streaks be determined?
 
Upvote 0
The formulas above in post 3 will only find the sum of the first streak of maximum length. Finding other equal length streaks and comparing values is probably beyond the scope of a single cell formula. I can see how it would be done with some helper cells, but that would still be pretty clumsy. I think a macro could do this cleaner.
 
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top