A1 = 6-Dec
B1 = 2
Goal: Repeat all the dates 7 times starting from 6-Dec (Value in 'A1') up to 2 weeks (Value in 'B1')
Formula Used :
=ArrayFormula(FLATTEN( split( REPT(SEQUENCE(7,1,A1,1)+SEQUENCE(1,B1,0,7)&"$",8),"$")))
Expected Result :
Two columns for two weeks. Each date of the week to be repeated 8 times.
Actual Result :
Only 1st week is repeated
Please help me in correcting the formula.
=ARRAYFORMULA(A1+TRANSPOSE(SEQUENCE(B1,7*8,0)/8))
A1: Date
B1: Weeks
SEQUENCE/TRANSPOSE to create a sequence of numbers increasing in the vertical direction
/8 Divide by 8 to create 8 fractional numbers for the same number.
Add the fractional numbers to the date A1 to create a date sequence repeated 8 times
FLOOR[optional] the fractional numbers, if exact dates are needed without time difference.
use:
=INDEX(TEXT(FLATTEN(TEXT(SEQUENCE(7, 1, A1), SEQUENCE(1, 8,,))),
SEQUENCE(1, B1,,))+SEQUENCE(1, B1,, 7))
Related
I have sales data that gives me dates in a bad format. Every new sale gets automatically added to the sheet. Looks like this:
Column A
Column B
Column C
Order 1
2022-12-02T02:09:37Z
$1025.19
Order 2
2022-12-02T01:25:15Z
$873.65
This will continue on for all sales. Now the date format is UTC for whatever reason and I can't adjust that, so within this formula I have to subtract 6 hours to get it to central time. I'm trying to create an auto-updating chart that shows an average day for 7 days, so I'm trying to do a sumif formula.
Here's what I have on Sheet2:
=sumif(Sheet1!C:C,index(split((index(split(Sheet1!B:B,"T"),1)+index(split(left(Sheet1!B:B,19),"T"),2))-0.25,"."),1),A1)
Where A1 is a single date. Testing this with one date and not the range shows that it does match. When I do the range, the total comes to 0, even though multiple different dates should match. What am I doing wrong?
Assume A1 has the value: 2022-12-02T02:09:37Z
Apply this formula:
=LAMBDA(RAW,TUNEHOUR,
LAMBDA(DATE,TIME,
TEXT((DATE&" "&TIME)+TUNEHOUR/24,"yyyy-mm-dd hh:mm:ss")
)(TEXT(INDEX(RAW,,1),"yyyy-mm-dd"),REGEXREPLACE(INDEX(RAW,,2),"Z",""))
)(SPLIT(A1,"T"),-6)
returns:
2022-12-01 20:09:37
And assume you have a set of data like this:
you can apply this formula:
=ArrayFormula(
LAMBDA(DATES,AMOUNTS,START,END,DFORMAT,TFORMAT,SKIPBLANK,TUNEHOUR,
LAMBDA(DATES,AMOUNTS,DTFORMAT,START,END,
LAMBDA(DATES,TIMES,
LAMBDA(VALIDDATES,AMOUNTS,
TEXT(SUM(FILTER(AMOUNTS,VALIDDATES>=START,VALIDDATES<=END)),"$#,##0.00")
)(TEXT((DATES&" "&TIMES)+TUNEHOUR/24,DTFORMAT),IF(ISNUMBER(AMOUNTS),AMOUNTS,VALUE(REGEXEXTRACT(AMOUNTS,"^\$(.+)"))))
)(TEXT(INDEX(DATES,,1),DFORMAT),REGEXREPLACE(INDEX(DATES,,2),"Z",""))
)(SPLIT(QUERY({DATES},SKIPBLANK),"T"),QUERY({AMOUNTS},SKIPBLANK),DFORMAT&" "&TFORMAT,TEXT(START,DFORMAT)&" 00:00:00",TEXT(END,DFORMAT)&" 23:59:59")
)($B$5:$B,$C$5:$C,$B$1,$B$2,"yyyy-mm-dd","hh:mm:ss","WHERE Col1 IS NOT NULL",-6)
)
Where you enter a start date and an end date at B1 & B2 to sum up the amount with.
The provided date column will be deducted by 6 hours.
What this formula does is...
format the date column into a valid date,
compare dates from step 1 with a given start and end date as filter condition,
filter the given amount column with conditions from step 2,
sum the result of filter from step 3 as an array,
format the output as price.
Use regexreplace() and query(), like this:
=arrayformula(
query(
{
weeknum(
regexreplace(B2:B, "([-\d]+)T(\d\d:\d\d).+", "$1 $2")
-
"6:00"
),
C2:C
},
"select Col1, avg(Col2)
where Col1 is not null
group by Col1
label Col1 'week #' ",
0
)
)
I think you're trying to split the values and sum them. I can't understand fully what's the purpose of 19 in LEFT function, and why are you again splitting it? Maybe some approach similar to yours is use LEFT function with 10 characters for the date, and MID from 12th character to get the time. Then substract .25 for the 6 hours as you did, and ROUNDDOWN with 0 digits to get the only the day
=ARRAYFORMULA(ROUNDDOWN(LEFT('Sheet1'!B:B,10)+MID('Sheet1'!B:B,12,8)-0.25,0))
And then you can insert it in your SUMIF:
=SUMIF(Sheet1!C:C,ARRAYFORMULA(ROUNDDOWN(LEFT(Sheet1!B:B,10)+MID(Sheet1!B:B,12,8)-0.25,0)),A1)
I'm trying to mod a formula in google sheet to substract a value based on the value of another column
Column E has the amount of hours: 3, 4, 5, 9 for example
If the hours are between 4 and 5 I need to substract 0.25 , if between 5 and 6 - 0.50 and if > 8 - 0.75
this is what I did:
=ArrayFormula(if(len(E2:E) ,(ifs((E2:E=0),IFERROR (1/0),AND(E2:E > 4 , E2:E < 6 , E2:E-0.25) or (E2:E > 6,E2:E < 8 ,E2:E-0.5) OR (E2:E > 8,E2:E-0.75)))))
could anyone please help me figuring out what I'm doing wrong? thank you
You can easily achieve this with vlookup.
Build a static array {} of two columns with your limits and results for the vlookup range:
={4,-0.25;5.0001,-0.5;6.0001,0;8.0001,-0.75}
Then a vlookup to test inputs. My input figs are in col G, and the vlookup is in an arrayformula in cell H1:
=arrayformula(if(G1:G<>"",iferror(vlookup(G1:G,{4,-0.25;5.0001,-0.5;6.0001,0;8.0001,-0.75},2,1),),))
You can then add the result to your existing formula.
UPDATE
This takes the hour value from col E and makes the required subtraction. Add this formula to cell F1 and clear all cells below:
=arrayformula({"Adjusted hours";if(E2:E<>"",E2:E+iferror(vlookup(E2:E,{4,-0.25;5.0001,-0.5;8.0001,-0.75},2,1),),)})
I am trying to convert a duration to a number. I have a cell that lists total hours and total minutes from a Google Meet. I am trying to automatically convert that information to the total number of minutes expressed as a number.
Ex: Cell 1(1 hr 8 min) to Cell 2 (68)
The google meet data, with the total hour/ total minutes) will be automatically pasted in from the meet report.
Is this possible?
If you have the duration always expressed as X hr Y min,
UPDATED:
= ARRAYFORMULA(
IFNA(
IF(LEN(B2:B),
REGEXEXTRACT(B2:B, "\d+") * 60 + REGEXEXTRACT(B2:B, "\D+(.+)min"),
""),
REGEXEXTRACT(B2:B, "\d+")
)
)
This part extracts the number before the hr and we multiply it by 60
REGEXEXTRACT(B2:B, "\d+")*60
This part extracts the number between hr and min and we add it to the above result:
REGEXEXTRACT(B2:B, "\D+(.+)min")
To adapt the formula to your situation, please consider the following notes:
Durations in the example starts from B2
Total is retrieved in C2:C
Arrayformula is used: i.e. only one formula is used in C2, and no need to copy the formula down
Supposing your original string were in A2, and that no meeting ran more than 9 hr 59 min, you could use this simple approach:
=TIME(LEFT(A2,1),MID(A2,6,2),0)*24*60
ADDENDUM (after more information added by poster)
This will cover your newly given scenarios:
=TIME(IFERROR(REGEXEXTRACT(A2,"(\d+) hr"),0),REGEXEXTRACT(A2,"(\d+) min"),0)*24*60
I have a column with weeknumbers incrementing from 1 to 42.
Next to it I would like to have the corresponding monthnumbers from 1 to 12.
So e.g. next to week 1, 2, 3 it would be month 1.
How would I achieve this in google sheets?
Best
Florian
A week number may span a month end, so two different months for different days in the same week. ie
Not possible.
It's possible if you'll count concrete dates.
A1:
=ARRAYFORMULA( (ROW(INDIRECT("a1:a"&42)) - 1) * 7 + today())
adjust the date, change today() to your start date.
B1:
=FILTER(WEEKNUM(A1:A,1),A1:A<>"")
adjust week type if needed, change 1
C1:
=FILTER(MONTH(A1:A),A1:A<>"")
1950 minutes is 32.5 hours. How do I calculate this using a formula in Google Sheets?
I am logging the number of minutes that I take on completing tasks and need a way of converting these numbers into the number of hours in Google Spreadsheets.
I have a column that contains rows of minutes, 1 row per task. This sum total of this column then needs to be added together, then converted into hours.
Here is a function that converts minutes in hour:minutes,
=if( A1 = 0 ; "" ; concatenate( quotient( A1 ; 60 ) ; ":" ;MOD(A1 ; 60) ))
62 --> 1:2
Use convert function to convert a numeric value to a different unit of measure
=CONVERT(A1; "mn"; "hr")
Documentation
Here is a function that converts minutes in hour:minutes:
=CONVERT(A1,"mn","hr")/24
Where A1 is the section you want to convert
Add up all the values using the function =SUM(number1,number2,number3,number4,...).
Example: =SUM(A1:A200) adds up all the numbers from A1, A2, A3 ... until A200.
Divide the total number of hours (it's located in the field with the =SUM function) by 60 (60 minutes in 1 hour, of course) with =DIVIDE(number1,number2)
Example: =DIVIDE(A201,60). In case you put the =SUM function in field A201, you divide the result of that field by 60.
Pierre's answer is mostly correct. However, it does not properly output the time if the number of minutes is below 0. If you need to handle a negative time amount, use the following formula instead:
=CONCATENATE(IF(AND(A1 < 0, A1 > -60), "-", ""), QUOTIENT(A1, 60), ":", TEXT(MOD(ABS(A1), 60), "00"))
I've improved it:
123 to proper 2h 3min
Do not show insignificant 0.
not show "0 mins" (number is completely divisible by 60) e.g. 120mins to 2h and NOT 2h 0min
not show "0h" (number is less than 60) e.g. 40min to 40min and NOT 0h 40min
To use just replace A1 with the cell number of the cell that contains mins.
=IF (A1=0, "", CONCATENATE ( IF(QUOTIENT(A1,60)=0, "", CONCATENATE (QUOTIENT(A1,60),"h ") ), IF(MOD(A1,60)=0,"",CONCATENATE (TEXT(MOD(A1,60),0),"min"))))