[Solved] Count consecutive positive numbers

Discuss the spreadsheet application
Post Reply
Sheen
Posts: 19
Joined: Mon Jul 24, 2017 10:22 am

[Solved] Count consecutive positive numbers

Post by Sheen »

There is a column with positive and negative numbers in random order. I would like to count the maximum streak of positive numbers and a maximum streak of negative numbers. For instance:
10
-5
2
56
-45
-50
-55
-32


MAx positive streak is 2, max negative is 4.
Last edited by MrProgrammer on Mon Jan 04, 2021 4:30 am, edited 1 time in total.
Reason: Tagged ✓ [Solved]
OpenOffice 3.1 Windows 7
User avatar
MrProgrammer
Moderator
Posts: 4906
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Count consecutive positive numbers

Post by MrProgrammer »

Sheen wrote: I would like to count the maximum streak of positive numbers and a maximum streak of negative numbers.
201812121141.ods
(10.56 KiB) Downloaded 133 times
If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the title. You can select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Count consecutive positive numbers

Post by Zizi64 »

Use one (or two) helper column for checking if the actual and the previous number has same sign or not. Flag and count the same negative number pairs with a negative counter, and flag and count the same positive number pairs with a positive counter. The different sign will reset the counters.

Finally you can search the MIN() The negative number with large absolute value, and the MAX() the positive number with large absolute value in the helper column/s/.

(SAME as suggested by MrProgrammer. I am too slow)
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
gerard24
Volunteer
Posts: 958
Joined: Sat Oct 30, 2010 5:12 pm
Location: France

Re: Count consecutive positive numbers

Post by gerard24 »

MrProgrammer solution is the best and easiest solution, but this can be done whithout helper.
This is an array formula, entered with Shift+Ctrl+Enter.

Code: Select all

=MAX(FREQUENCY(IF(A1:A8>0;ROW(A1:A8));IF(A1:A8<0;ROW(A1:A8))))
LibreOffice 6.4.5 on Windows 10
Post Reply