How to create a long run program [duplicate] - google-sheets

This question already has answers here:
Google Sheets - How to count streaks of non-zero numbers on one column
(2 answers)
Closed 2 months ago.
I'm trying to create a formula, likely used in Google Sheets, that will count the number of consecutive "hits" forward from the first recorded event and then another that will count in reverse from the last recorded event.
Example
X X X X X X X X O X
In this example, the consecutive hits forward would be "8" and the consecutive hits in reverse would be "1"
I have been unsuccessful in coming up with a formula

try:
=LEN(SPLIT(SUBSTITUTE(A1, " ", ), "O"))
and
=INDEX(LEN(SPLIT(SUBSTITUTE(A1, " ", ), "O")),,COLUMNS(SPLIT(A1, "O")))

Related

Repeat A1:A4 n times [duplicate]

This question already has answers here:
Repeat range of items multiple times in Google Sheets
(5 answers)
Repeat whole row N times based on column value in Google Sheets
(2 answers)
Repeat each row N times in Google Sheets
(4 answers)
Closed 5 months ago.
I've searched and cant find the answer to this seemingly easy task
I'm looking to repeat A1:A4 n times
A1:A4=
California
Off
Texas
Off
Desired output: n=4
California
Off
Texas
Off
California
Off
Texas
Off
California
Off
Texas
Off
California
Off
Texas
Off
There are multiple ways to repeat text in columns:
Solution 1:
=FLATTEN(TRANSPOSE(ARRAYFORMULA(SPLIT(REPT(A1:A4&";",B1),";"))))
Where B1 is the number of the repetition.
Solution 2:
You may also use Join
=transpose(split(rept(join(",",A1:A4)&",",4),","))
Solution 3:
You can also use TextJoin
=FLATTEN(split(REPT(TEXTJOIN("^",TRUE,(A2:A),"^"),B2),"\^"))
Result:
try:
=INDEX(FLATTEN(TEXT(TRANSPOSE(A1:A4); FLATTEN(SPLIT(REPT("#×"; 4); "×")))))
or see: https://stackoverflow.com/a/54266697/5632629

How do I convert a duration string to number? [duplicate]

This question already has answers here:
ultimate short custom number formatting - K, M, B, T, etc., Q, D, Googol
(3 answers)
Closed 8 months ago.
In a Google sheet, I have a list of rows with a length attached to each:
Example 1 - 1h 30m
Using a formula, I need to convert "1h 30m" to a numerical value.
The longest duration I have in the sheet are 4 digit durations (ie 1000h 30m)
Does anyone know how to best do this?
Assuming the text string 1h 30m is in cell B2, use a regexreplace() formula in another cell, like this:
=to_date( value( regexreplace(B2, "(\d+)h (\d+)m", "$1:$2") ) )
Format the formula cell as Format > Number > Duration or a custom time format of your choosing.
See this answer for an explanation of how date and time values work in spreadsheets.
To learn the exact regular expression syntax used by Google Sheets, see RE2.

How to Repeat a Data Set (several columns) x times in Google Sheets [duplicate]

This question already has answers here:
Repeat whole row N times based on column value in Google Sheets
(2 answers)
Closed 5 months ago.
The idea here is to create a backup table to enable a faster filling of repeated information in another worksheet.
Dataset:
Exam Parameter Step System Samples
b-HCG OD Calibration 1 5
TSH OD Calibration 2 3
where Col1 = Exam, Col2 = Parameter, Col3 = Step, Col4 = System
enter image description here
So I've been trying to repeat each line x times. X is defined by the nº of samples in each analysis and I would like to return the repeated set in a merged table. For example, all info in row 1 repeated 5 times, row 2 repeated 3 times and so on.
To make a dynamic formula, I tried the following:
=TRANSPOSE(SPLIT(REPT(B3&"|";F3);"|"))
=TRANSPOSE(SPLIT(REPT(C3&"|";F3);"|"))
=TRANSPOSE(SPLIT(REPT(D3&"|";F3);"|"))
=TRANSPOSE(SPLIT(REPT(E3&"|";F3);"|"))
enter image description here
By this I can get the repeated set but just for the first row. If I try to autofill the remaining rows with the above formula, the original formula is overwritten, and I get the repeated data set for the 2nd row instead.
Can I solve this with native formula only or is this only manageable by JavaScript?
try:
=INDEX(SUBSTITUTE(SPLIT(FLATTEN(SPLIT(QUERY(REPT(FLATTEN(
QUERY(TRANSPOSE(SUBSTITUTE({"♦"&A2:A, B2:D}, " ", "♠")),,
9^9)), E2:E),,9^9), "♦")), " "), "♠", " "))

How to make a custom number formatting for trillions in google sheets [duplicate]

This question already has answers here:
ultimate short custom number formatting - K, M, B, T, etc., Q, D, Googol
(3 answers)
Closed 1 year ago.
I found this online which formats thousands, millions, and billions
[<999950]0.0,"K";[<999950000]0.0,,"M";0.0,,,"B"
number format sheet
how would you format it so it's by millions, billions, and trillions
Link to sheet
this "internal" formatting is by default able to work with only 3 types of numbers:
positive (1, 2, 5, 10, ...)
zero (0)
negative (-3, -9, -7, ...)
this can be somehow tweaked to show custom formatting like K, B, M but you always got only 3 slots you can use, meaning that you can't have trillions as the 4th type/slot
[<999950000]0.0,"M";[<999950000000]0.0,,"B";0.0,,,"T"

How do i detect count of 'x' in cells and count of longest continued series of 'x'?

I am creating Google Sheets spreadsheet inspired from here. It is habit tracking spreadsheet. .User need to write x if current day is successful. The function detects longest continuous series of 'x', and displays steak(ount of longest continued series of 'x'). I would like to use this functionality locally on my machine. I am not able to modify the offset function in the sheet.
No Habit Steak Max 02/02/2016 02/03/2016 02/04/2016
1 Habit1 1 3 x x x
2 Habit2 2 2 x x x
3 Habit3 5 10 x x x
Here No is numbering field.
Habit is name of habit being tracked.
Steak is the total continuous days on which x is found. If there is one space, steak is broken.
Max is maximum numbers of days the x was continued.
Rest columns are days with date as heading.
I need the function to calculate steak and max.
The following formula will give you the max continuous series of 'x' for a activity. Copy it down for the number of activities you have.
=iferror(if(countif($D2:2,"x")=0,0,max(arrayformula(len(split(concatenate(transpose(arrayformula(if($D2:2="x","x","|")))),"|"))))))
Reviewed version of the formula proposed in the answer by Ed Nelson
The following formula will give you the max continuous series of 'x'
for a activity. Copy it down for the number of activities you have.
=if(
countif($D2:2,"x")=0,
0,
max(
arrayformula(
len(
split(
concatenate(
transpose(
arrayformula(
if($D2:2="x","x","|")
)
)
),
"|"
)
)
)
)
)
Notes:
The above formula should be added to row 2. If it will be added to another row update the row reference accordingly.
It's assumed that only the cells to be used to track habits will have a "big fat X".
Guys from the forum forum.Chandoo.org made formulas and created sample sheet. This works exactly like i wanted. this is the thread link.
The formulas are:
for Cell C2 = LOOKUP(99,FREQUENCY(IF(E2:T2<>"",COLUMN(E2:T2)),(E2:T2="")*COLUMN(E2:T2)))
For Cell D2 = MAX(FREQUENCY(IF(E2:T2<>"",COLUMN(E2:T2)),(E2:T2="")*COLUMN(E2:T2)))
This works. There is reference link for the formulas,here.

Resources