Multiplying Duration - google-sheets

I have a spreadsheet with, in one column a duration express using the following format:4:36. 4 minutes and 36 seconds. I would like to multiply it with a number representing the number of views on the video. For instance, the spreadsheet would look like this:
1876|4:36
What shall I put in the next cell to multiply the two, ultimately I would like to have the result in the format: "HH:mm:ss".

try:
=TEXT(((REGEXEXTRACT(TO_TEXT(B1), "^\d+")*60+
REGEXEXTRACT(TO_TEXT(B1), "\d+$"))*A1)/1440/60, "[h]:mm:ss")

Related

RUNNING TOTAL with ARRAYFORMULA that can SUM and SUBTRACT if cell values changes

I'm trying to calculate the cumulative total in a column. It needs to sum or subtract if the value of (A) cell is set to buy or sell. here is an example:
A (task)
B (qtty)
C (total)
calculation explanation
buy
10
10
sum 10
buy
10
20
sum 10
sell
5
15
subtract 5
buy
20
35
sum 20
sell
10
25
subtract 10
I´m using the folowing formula:
={"Total", ARRAYFORMULA(IF(LEN(A2:A),IF(A2:A="buy",SUMIF(ROW(B2:B),"<="&ROW(B2:B),B2:B), "NEED CODE FOR SELL" ),))}
Is there another way to do the calc?
I don't want to use negative values to subtract, because the values are used in other formulas.
Thanks in advance.
try this:
=SCAN(0,A2:A,LAMBDA(ac,cv,if(cv="",,ac + ifs(cv="buy",OFFSET(cv,,1),cv="sell",-OFFSET(cv,,1)))))
You can use SCAN:
=ArrayFormula(IFNA(SCAN(,A2:A&B2:B,LAMBDA(tot,cur,tot+REGEXEXTRACT(cur,"\d+")*IF(REGEXMATCH(cur,"(?i)buy"),1,-1)))))
Or:
=SCAN(,B2:B,LAMBDA(tot,cur,IF(cur,tot+IF(INDEX(A2:A,ROW(cur)-1)="buy",cur,-cur),)))
It's also possible to do it with Sumif:
=ArrayFormula(if(A2:A="",,
sumif(row(A2:A)*if(A2:A="buy",1,9^9),"<="&row(A2:A),B2:B)-
sumif(row(A2:A)*if(A2:A="sell",1,9^9),"<="&row(A2:A),B2:B)))
Of course, there's no particular reason for doing it this way now that you have lambdas. I'm including it for old time's sake as I was one of the first people to use Sumif in this way.

Google Sheets: Is there a way to make an Array for a sequence that grows to a repeat given number of times

I have managed to make this formula:
=IF(COUNTIF($A$1:A1,A1)=$B$1,A1+1,A1)
Is making an incremental list in the same column, starting with 01, and on cell B1 I am instructing how many times this number should repeat (up to 5 times per number). So, if I say repeat 2 times it looks like this:
Column A
1
1
2
2
How can I make it an Array Formula? I'm barely starting on Arrays so I'm just trying to learn as I go.
you can try to solve this with the following formula =ArrayFormula(flatten(if(SEQUENCE(1,C1),SEQUENCE(C2)))) but you should specify the value limit in cell C2 to which the numbers must increase, otherwise the formula will loop
Try this
=ARRAY_CONSTRAIN(arrayformula(query(flatten(split(rept("|"&A2:A,B2:B),"|")),"select * where Col1 is not null")),SUM(B2:B),1)
https://docs.google.com/spreadsheets/d/1qXy-hzWUnsUmAa-8aV5IHOyZABGD_h8ajICLwdyNge8/edit?usp=sharing
Try Sequence() with ROUNDUP() function.
=ArrayFormula(ROUNDUP(SEQUENCE(B1*B1)/B1,0))
When enter 3:

How to generate a repeating sequence of numbers in google sheet?

So what i need is quite simple, yet somehow i cant get around to find a solution for it.
Basically what i need is for a column, starting from its 2nd row to look list numbers from 1 to 15 and have that sequence repeated all the way to the bottom of the sheet automatically. i was thinking about using arrayformula but couldnt figure out the formula for it.
essentially something like this but it goes all the way down automatically.
Explanation:
You can repeat (REPT) a sequence of numbers from 1 to 15 by using the Sequence formula.
The maximum number of times you want to repeat this sequence will be determined by the total number of rows in your sheet divided by 15.
Solution:
=transpose(split(REPT(concat(JOIN(",",SEQUENCE(1,15)),","),ROUNDDOWN(ROWS(A1:A)/15)),",",true))
Output:
non-REPT solution:
=INDEX(ARRAY_CONSTRAIN(FLATTEN(
SEQUENCE(ROUNDUP(ROWS(A:A)/15), 15)-(
SEQUENCE(ROUNDUP(ROWS(A:A)/15), 1, 0)*15)), ROWS(A:A)-ROW()+1, 1))

Converting textdata from strava/zapier to use in calculations

I have a zap # Zapier which automatically imports my Strava activity to Google Sheets. This works fine, but it inputs everything as text. I want to be able to calculate my running (accumulated) average pace, but it is not possible with the data as is. So, do any of you have any formulaes for converting the info in column G to proper google sheets time format so that I can use it for calculations?
Here is a link to the data: https://docs.google.com/spreadsheets/d/1UD25--vrVgVp0AuhLFi7CGWFIo-GHeLfD_n8WqDbNrE/edit?usp=sharing
Try this formula in any blank column on row 2.
=(value(left(G2;len(G2)-3)) + value(right(G2;2))/60)/60/24
This parses the time value, eg 2:34, in column G, extracting the minutes from in front of the colon, and the seconds from after the colon, converts them from text to numbers, adds them together, and divides by 60 to get hours, and by 24 to get fractions of a day. Is this what you want?
For a formula that will do the whole column, place the following in row 1 of a blank column, and format the column for Time:
={"Time";arrayformula((value(left(G2:G;len(G2:G)-3)) + value(right(G2:G;2))/60)/60/24)}
Let me know if you need something else.

Repeating time windows in Google Spreadsheets?

I'd like to insert time windows repeatedly in a column, like this:
10:00-10:20
10:20-10:40
10:40-11:00
11:00-11:20
11:20-11:40
12:00-12:20
Is there a way to achieve this?
Put data in cells:
B1 = 10:00 (start time)
B2 = 12:20 (end time)
B3 = 20 (interval in minutes)
Here's single arrayFormula, that will generate your column:
=ARRAYFORMULA(TEXT(B1+B3*1/24/60*(row(OFFSET(B8,,,(B2-B1)/(B3*1/24/60)))-row(B7)-1),"HH:MM")&"-"&TEXT(B1+B3*1/24/60*(row(OFFSET(B8,,,(B2-B1)/(B3*1/24/60)))-row(B7)),"HH:MM"))
Explanations
Look at sample file to explore more about this formula. Pay attention on some details:
any kind of logical sequence could be done with help of series 1,2,3... Formula like =ARRAYFORMULA(row(OFFSET(B8,,,7))-row(B7)) gives us column from 1 to 7.
Time treated like numbers in sheets: 1 day is 1, 1 hour is 1/24, 1 minute is 1/24/60 and so on
Time can't be properly converted into text as it's number. So you have to use text(time, "HH:MM") formula to convert time into text.
This will repeat your time window. The formula assumes the time range is in A2:A6.
The 3 in the formula is the number of repeats (change to you need). You might want
to consider placing A2:A6 on another sheet and referencing it in the formula.
=TRANSPOSE(SPLIT(JOIN(",", ARRAYFORMULA(SPLIT(transpose(rept(join(",",A2:A6)&",",3)),",")&",")), ","))

Resources