How to find the value in a cell after consecutive positive numbers - google-sheets

I have a list here of numbers, positive and negative, from A3:A17. I want to find the value after a consecutive streak of positive numbers. So in the picture above, there's a streak of two consecutive positive numbers from A5 to A6, 2.60% and 1.10%, respectively. I want to get the number after that, which is -1.90%. But if there's another streak of two positive numbers, I want the formula to be able to identify that too. I have a formula to identify the streak but not one to identify the number that comes after it.

Try these in cell B3 (deleting everything below):
Any occurrences:
=arrayformula(if(A3:A<0,if(A2:A>0,if(A1:A>0,A3:A,),),))
2 occurrences:
=arrayformula({"";if(A4:A<0,if(A3:A>0,if(A2:A>0,if(A1:A<0,A4:A,),),),)})
3 occurrences:
=arrayformula({"";"";if(A5:A<0,if(A4:A>0,if(A3:A>0,if(A2:A>0,if(A1:A<0,A5:A,),),),),)})
4 occurrences:
=arrayformula({"";"";"";if(A6:A<0,if(A5:A>0,if(A4:A>0,if(A3:A>0,if(A2:A>0,if(A1:A<0,A6:A,),),),),),)})

=ArrayFormula(QUERY(IF(A3:A>0,IF(A4:A>0,A5:A,),),"select Col1 where Col1 is not null",0))

Try this in cell B3 and autofill downward:
=IF(A1>0,IF(A2>0,A3,""))

Related

Sum two ranges separately in one formula

How can I do one single formula to sum two ranges and display them in their respective column.
Here I'm using SUM formula in each cell but I'm sure there must be a single formula that can accomplish this.
Value 1 and Value 2 are the ranges to add them together in Sum row.
Here is an example picture.
Since arrayformula does not support sum, I suppose you could also do this in C12:
=arrayformula(C10:I10+C11:I11)
Clear the formula you have in row 12 and then enter in C12
=index(mmult({1,1}, --C10:I11))
Change range to suit and see if that helps?

Adding the first digit(s) of a cell ending with specific letter

I have a sheet that has blocks of cells. I add them for a total if they don't contain any letter. Letters signify a specific variable or signifier code for tracking. I also want to add the cell value when a cell has an ending code letter. I've tried SUMIF, Substitute, SumProduct and a few others.
For a while I've used the following which worked till the S value changed to another number than "8" which then gave the wrong sum from the range.
=if(countif(D64:Q64,"*S")=0,"",((countif(D64:Q64,"*S"))*8))
In the cell range I have 5 variable groups ending in a letter (A, H, S, C and R) and one group not ending in any letter.
The formula I use to add the cells not containing a letter but have a value is this
=IF(SUM(AA64,(SUMIF(D65:Q65,"<>")),-(COUNTIF(D65:Q65,">=0")*8))>24,24,(SUM(AA64,(SUMIF(D65:Q65,"<>")),-(COUNTIF(D65:Q65,">=0")*8))))
which adds the table data plus the previous lines table data but does not exceed 24.
H is a set value of 6 and doesn't change.
Does anyone know how to add the value of the cells that contain a specific letter?
N (number)
A
S
C
R
H
8.5
H
8A
2S
9
3C
0.5R
17.5
8
2
3
0.5
6
I'd prefer it be a formula usable in Google Sheets because that is where this data is.
Solution:
You can use this formula below column "N" then drag right until below column "H".
=SWITCH(H$1,"N",SUM($A2:$G2),"H",6,SUM(IFERROR(ARRAYFORMULA(VALUE(LEFT($A2:$G2,FIND(H$1,$A2:$G2)-1))),0)))
This is a combination of three formulas:
If the row above is N, sum A2 to G2. This will ignore all the strings.
If the row above is H, output 6.
Else, get the number to the left of the defined suffix, set all others to 0, and get the sum.
Output:
References:
Extract number from string in Google Sheets
An alternative could be to use
=SUMPRODUCT(A3:G3, isnumber(A3:G3))
to compute the sum of the cells with numbers only, and to use
=sum(filter(substitute($A$3:$G$3, I$2,)+0, regexmatch($A$3:$G$3, I$2)))
under the 'A' and drag to the right
Examples

Count number of times values increase in range - Google Sheets

how are you? I'm just not sure what to do here, but I surely can use your help!
I have a series of values in a row range, such as in the following:
1000 2000 1500 2100 3200
I need to figure out a google sheets formula to put in the 6th cell of this row that counts the number of times the value of any cell is greater than the one to the left of it. In this example, my result should be 3.
Is there any way that this can be done? In Excel or Google Sheets, either is great to learn.
Thank you
You can also try the following formula
=COUNTIF(QUERY({{"";TRANSPOSE(B2:F2)},{TRANSPOSE(B2:F2);""}},
"select Col1-Col2 offset 1 label Col1-Col2 ''",0), "<0")
Assuming you have data in A2:E, place the following in F2:
=ArrayFormula(IF(A2:A="",,MMULT(IF(B2:E>A2:D,1,0),SEQUENCE(4,1,1,0))))
Since there are only four columns that might be greater than others (B:E), you can structure it this way. MMULT is hard to explain, but it essentially multiplies everything in each row of one matrix (range) by everything in another range and then adds them. SEQUENCE just forms a column of four 1's by which to multiply then add together everything in each row of the first range. Since anything times 1 is the original number, this just serves to to row-by-row addition.
This formula will process as many rows as have data in A2:E.
try in 7th column on row 2:
=ARRAYFORMULA(MMULT(IF(A2:E4<B2:F4, 1, 0), {1;1;1;1;1}^0))

How do I create an arrayformula to calculate the median of three different values from one row?

How do you create an arrayformula to calculate the median of three different values from one row in google sheet?
For example, I want to do ARRAYFORMULA for MEDIAN formula.
=ARRAYFORMULA(MEDIAN(A2:A,$B$2,$C$2))
where
A2: start date - 2020-07-22 10:00
B2: start hour - 8:00
C2: end hour - 17:30
And the result of MEDIAN(A2:A,B2,C2) is 10:00, but ARRAYFORMULA does not work. (the result is 00:00:00)
is it possible to make an Array for MEDIAN? Or is there any option to do that in other way?
Mean and median are not the same. Mean is essentially AVERAGE, while MEDIAN is the "middle-most" value in a set:
=AVERAGE(2,1,9) returns 4 [i.e., (1+2+9)/4 ]
=MEDIAN(2,1,9) returns 2 (i.e., the value in the middle if all the numbers were lined up from lowest to highest)
If you only have to compare three columns, you could get by with a sort of "brute force" value-to-value comparison array. For instance, in D2:
=ArrayFormula(IF(((A2:A-INT(A2:A)<B2:B)*(A2:A-INT(A2:A)>C2:C))+((A2:A-INT(A2:A)>B2:B)*(A2:A-INT(A2:A)<C2:C)),A2:A-INT(A2:A),IF((B2:B<(A2:A-INT(A2:A))*(B2:B>C2:C))+(B2:B>(A2:A-INT(A2:A))*(B2:B<C2:C)),B2:B,C2:C)))
In English, this says:
"If the first value is lower than the second AND higher than the third, OR if the first value is higher than the second AND lower than the third, it is the median. Return the first value.
If neither of those is true, check to see if the second value is lower than the first AND higher than the third, OR if the second value is higher than the first AND lower than the third. If so, it is the median. Return the second value.
If nothing has been true so far, then the third value must be the median. Return the third value."
The one additional thing is you'll notice I have E2:E-INT(E2:E). This gets rid of the date portion and leaves only the time, since in Google Sheets, dates are whole numbers while times are decimal portions less than 1. So removing the INTeger (i.e., whole) part of the cell value leaves only the decimal portion, which is the time. This is necessary so that the comparisons can be of-a-kind.
arrayformula for average:
=ARRAYFORMULA(TEXT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(N(A2:C*1)),
"select "&TEXTJOIN(",", 1, IF(A2:A="",,
"avg(Col"&ROW(A2:A)-ROW(A2)+1&")"))&"")),
"select Col2"), "hh:mm"))
arrayformula for MEDIAN now possible:
=IFERROR(BYROW(A2:C10, LAMBDA(xx, TEXT(MEDIAN(xx), "hh:mm"))))

Use text in a cell as plus and minus

I have a sheet with multiple rows. There is a cell on each row that says "In" and "Out" in a dropdown. Basically this is plus and minus. Next to that I have a cell that that holds an amount.
So it looks like this:
Item 1, In, 10
Item 2, Out, 5
This totals a profit of 5.
How can I with this setup calculate the total profit/loss for all the cells in the sheet depending on multiple in/out rows?
An if formula will calculate the rows and a sum formula will calculate the column.
First make the numbers positive and negative values.
=IF(B2="In",C2,C2*-1)
This formula in 'D2' checks if the value of 'B2' is "In".
If yes then just adds the value of 'C2'.
If no then it multiplies the value of 'C2' by negative one.
Second step is to add up the numbers.
=SUM(D2:D3)
Cell 'D4' sums the column.

Resources