Google sheets calculation for a period of time, please assist - google-sheets

Use sumifs to calculate "the profit" on "monday" between 0:00 and 1:00.
C:C profit, A:A date and B:B time. The function below does not return anything
=SUMIFS(C1:C1000,A1:A1000,"Monday",B1:B1000,">=00:00",B1:B1000,"<01:00")
Can someone assist me by using google sheets calculation the output being profits made between different times and for days of the week? Below is the sample data
Below is the blank sheet maker
https://docs.google.com/spreadsheets/d/1c6CcaUyry48kogVNmyogFytjGiRWwXIKO7_ikwLik4k/edit

One way to do that is to use filter(), like this:
=sum(
filter(
A2:A,
text(B2:B, "ddd") = "Mon",
value("0:00 am") <= C2:C, C2:C < value("1:00 pm")
)
)
The formula above assumes that profits are in column A2:A, dates in column B2:B and times in column C2:C as per the table shown in the question. In the event those values are in a different order in the columns suggested by the formula in the question, use this instead:
=sum(
filter(
C1:C,
text(A1:A, "ddd") = "Mon",
value("0:00 am") < B1:B, B1:B < value("1:00 pm")
)
)
You can also use named ranges, like this:
=sum(
filter(
Profit,
text(Date, "ddd") = "Mon",
value("0:00 am") <= Time, Time < value("1:00 pm")
)
)
The three named ranges must be exactly of the same height.
If the spreadsheet locale is such that the name of Monday is something else, replace Mon with something else. You should also use 24-hour time format such as 13:00 instead of 01:00 pm when the locale so requires.
The layout of data in your sample spreadsheet differs considerably from what you present in the question. Further, the values in column P are not dates but text strings that just look like dates.
With those handicaps, you can best get an hourly report pivoted by day of week using a couple of helper columns and query(), like this:
=arrayformula(
lambda(
daySerial,
if(
len(daySerial),
weekday(daySerial, 2) & text(daySerial, " dddd"),
iferror(1/0)
)
)(
iferror(value(substitute(P2:P, ".", "/")))
)
)
=arrayformula(
if(
len(Q2:Q),
value(regexextract(to_text(Q2:Q), "\d+")),
iferror(1/0)
)
)
=query(
N1:U,
"select U, sum(N)
where U is not null
group by U
pivot T",
1
)
See your sample spreadsheet.

Related

Comparing Dates in Google Sheets with different format

I tried everything and can't make this work.
File 1 has a date and transactions.
File 2 has date and other exported date from a software, so Column A is a date that is not formatted.
Basically I want to get the number of transactions per day on file 1, when in file 2 we have Column B with "google / cpc" and Column C contains "search".
The problem here is that I can't make the dates from File 1 to File 2 to compare to give me the transactions. It never compares.
File 1 https://docs.google.com/spreadsheets/d/1Xvoo2Rob3kI4duPpmCTfhMLPlvdzIJY9ZQBV7CHccoc/edit?usp=sharing
File 2 https://docs.google.com/spreadsheets/d/10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco/edit?usp=sharing
I tried to make the date from file 2 like the date from file 1 using concatenate and LEFT and RIGHT formulas, but they look similar to the eye, but google sheets can't compare.
I tried to also change the format to date and play with it, but still can't get them to compare the dates.
you can try this out:
=MAKEARRAY(31,1,LAMBDA(r,c,INDEX(LAMBDA(z,SUM(IFNA(FILTER(INDEX(z,,6),INDEX(DATE(LEFT(INDEX(z,,1),4),MID(INDEX(z,,1),5,2),RIGHT(INDEX(z,,1),2)))=INDEX(A3:A33,r),INDEX(z,,2)="google / cpc",REGEXMATCH(INDEX(z,,3),"(?i)search")))))(importrange("10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco","Sheet2!A:F")))))
they look similar to the eye, but google sheets can't compare
The values like 20230102 in spreadsheet 2 column A look like dates but are actually numbers in the neighborhood of 20 million, such as 20,230,102.
It is unclear whether your intention is to use that data in just this one report or several such reports. If the latter, you may want to Insert > Sheet in spreadsheet 1 and put this formula in cell A1 of that new 'Import' sheet to import and convert the data:
=arrayformula(
lambda(
ssId, datelikeRangeA1, criteriaRangeA1, transactionsRangeA1,
lambda(
dates, criteria, transactions,
query(
{ dates, criteria, transactions },
"select Col1, sum(Col3) where Col2 = 'google / cpc' group by Col1
label Col1 'Date', sum(Col3) 'Total transactions' ",
0
)
)(
to_date( value( regexreplace(
to_text( importrange(ssId, datelikeRangeA1) ),
"(\d{4})(\d{2})(\d{2})", "$1-$2-$3"
) ) ),
importrange(ssId, criteriaRangeA1),
importrange(ssId, transactionsRangeA1)
)
)(
"10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco",
"Sheet2!A2:A",
"Sheet2!B2:B",
"Sheet2!F2:F"
)
)
The formula may look a bit complex, but it is easy to adjust to other similar imports you may need by modifying the parameters at the end. You can then more easily to refer to the data in your various reports. To match the dates in Sheet1!A3:A33, put this formula in cell Sheet1!B3:
=arrayformula(
ifna(
vlookup(
A3:A33,
Import!A2:B,
columns(Import!A2:B),
false
)
)
)
Using your current formula,try changing your values with text and back to number with value:
=INDEX(IFNA(VLOOKUP(VALUE(TEXT(A3:A33,"yyyymmdd")), QUERY(IMPORTRANGE("10Enq805we6_XcTkytwfj6ON1ZnITnAGUwLVoaGzXeco", "Sheet2!A:N"),
"select Col1,sum(Col6) where Col2 = 'google / cpc' and Col3 = 'search' group by Col1"), 2, 0)))

VLOOKUP with 2 columns for both search_key and range

I am struggling to find a way to use a VLOOKUP where the both the search_key and range are 2 columns. In both sheets (seperate workbooks for which I am using IMPORTRANGE) I have 2 columns with First Name and Last Name. The Sheet1 also contains the Hire Date, and I would like to populate the Hire Date from Sheet1 into a column in Sheet2.
I accomplish what I want if I merge the First Name and Last Name into a single column on both sheets. Unfortunately, this cannot be a permanant solution since there are other dependancies where the names must remain seperate columns.
I have created a test worrkbook to showcase the issue.
https://docs.google.com/spreadsheets/d/1v3coBJRwJEbrrdgcflV4-dssKgknS-T2werWVjPwxEA
Put this formula in cell Sheet2!C1:
=arrayformula(
iferror(
vlookup(
A1:A & B1:B,
{ Sheet1!A1:A & Sheet1!B1:B, Sheet1!C1:C },
2, false
)
)
)
Then format the result column as Format > Number > Date.

Google Sheets COLUMN TOP ArrayFormula to calculate ROW wise which require ROW-wise ArrayFormula

Ref link below.
Essentially the aim to get a geometric progression with each term repeated X times.
The correct result on the sheet is obtained using an ArrayFormula across a row. This requires copying the formula column wise.
What I would like is a single ArrayFormula atop the column, that calcluates the results row wise (as indicated). My attempt on the sheet fails.
sheet link
New tab on your sample sheet called MK.Help. This formula is in cell E1.
It uses what I (and some others probably) call a query header smush. it takes advantage of query()'s built in ability to concatenate multiple header rows. It feeds a Transposed array into a query, then pretends like the whole thing is all header rows by setting the 3rd parameter of QUERY() equal to a very large number. It's common with this trick to use 9^9 or 9^99 which is just a very concise way of writing a very large number (9 to the 99th power).
=ARRAYFORMULA(
IF(
ROW(A:A) = 1,
"Result",
TRANSPOSE(
SUBSTITUTE(TRIM(
QUERY(TRANSPOSE(
REPT(
IF(
SEQUENCE(1,MAX(C:C),0) > C:C,,
ROUND(A:A * B:B ^ SEQUENCE(1,MAX(C:C),0)) & CHAR(10)
),
D:D
)
),, 9^9)
), CHAR(10), ",")
)
)
)
Same solution as Matt's, the only difference is that repetition is done using regex.
Try this (on sheet kishkin):
=ARRAYFORMULA(
IF(
A2:A = "",,
REGEXREPLACE(
REGEXREPLACE(
TRANSPOSE(QUERY(TRANSPOSE(
IF(
SEQUENCE(1, MAX(C2:C)) > C2:C,,
ROUND(A2:A * B2:B ^ SEQUENCE(1, MAX(C2:C),)) & ","
)
),, MAX(C2:C))),
"[^,\s]+,?",
REPT("$0", D2:D)
),
"\s+|,\s*$",
)
)
)

Google Sheets Formula: Sum if Substring in range of cells

I have two columns:
Col A Col B
01.02.2020 17
03.11.2020 24
03.11.2020 12
I tried to sum Col B, based on the substring of Col A like so:
=SUMIF(A:A,MID(A:A,4,2)="02",B:B)
=SUMIF(A:A,MID(A:A,4,2)="11",B:B)
Which means: If it's the second (XX.02.XXXX) month, it should sum the values from Col B based on that. If it's the 11th month (XX.11.XXXX) in Col A, it should do the same but for cells where Col A has 11.
However, it doesn't work. Apparently, one cannot do the MID function over more than one cell?
You need to use ARRAYFORMULA for that.
This one will give a column of sums for every month there is:
=ARRAYFORMULA(
SUMIF(
MID(A:A, 4, 2),
UNIQUE(MID(FILTER(A:A, A:A <> ""), 4, 2)),
B:B
)
)
And if you have those dates formatted as date, having the type date, then you can use MONTH instead of MID to get the month number:
=ARRAYFORMULA(
SUMIF(
MONTH(F:F),
UNIQUE(MONTH(FILTER(F:F, F:F <> ""))),
G:G
)
)

Indirect formula to find MIN of matching range

I have a spreadsheet with two sheets, first sheet contains Name (col:C), and Finish time (col:G), second sheet I have a column also called Name (col:A) , and a column called Personal Best Time (col:G).
Currently, in Sheet2:Col:G, i'm using a formula to search Sheet1 for the lowest Finish time value relating to that particular row's Name column (as below):
=ArrayFormula( min( if('Sheet1'!C:C = A2, 'Sheet1'!G:G) ) )
But for every row in Sheet2, this formula needs to be copied, with the only difference being the A2 reference (which is referring to the Name column of the current row).
So my hope was to create an indirect formula, where the specific range is entered in the header column, and automatically applied to each row.
So this is what I have so far:
=ArrayFormula( IF( ISBLANK(A:A), "", IF( ROW(G:G)=1, "Personal Best Time", ArrayFormula( min( if( 'Sheet1'!C:C = A2, 'Sheet1'!G:G ) ) ) )))
But how do I make it so that A2 changes depending on the row number?
I tried A:A, but if I'm right, that would be attempting to compare the whole Name column from Sheet2.
Does this formula work as you want:
=ArrayFormula( IF( ISBLANK(A:A), "", IF( ROW(A:A)=1, "Personal Best Time", ArrayFormula(Vlookup(A:A,SORT({Sheet1!C:C,Sheet1!G:G},2,1),2,0)))))

Resources