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.
[Solved] Count consecutive positive numbers
[Solved] Count consecutive positive numbers
Last edited by MrProgrammer on Mon Jan 04, 2021 4:30 am, edited 1 time in total.
Reason: Tagged ✓ [Solved]
Reason: Tagged ✓ [Solved]
OpenOffice 3.1 Windows 7
- MrProgrammer
- Moderator
- Posts: 4906
- Joined: Fri Jun 04, 2010 7:57 pm
- Location: Wisconsin, USA
Re: Count consecutive positive numbers
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.Sheen wrote: I would like to count the maximum streak of positive numbers and a maximum streak of negative numbers.
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).
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).
Re: Count consecutive positive numbers
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)
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.
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.
Re: Count consecutive positive numbers
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.
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