I am using Google Sheets and am trying to find the largest value for cells that contain a specific year.
Example:
A B
DATE Value
1 jan 1875 4000
1 jan 1880 800
5 feb 1875 3500
6 jun 1875 2500
I have read about the MAXIFS function but am unsure how to apply it in this situation.
MAXIFS(B2:B4;A2:A4;1875) only returns "0" when I want it to return "4000" in B2.
I have tried substituting the "1875" in the formula with "YEAR(1875)" but it doesn't work.
It might be an issue with the dates being before 1900 but I've tried using years after 1900 as well, still it won't work.
Anyone here who knows?
I suggest a query instead of MAXIFS:
=query(A:B,"select max(B) where A contains 1875")
Related
I have this row in Google Sheets with the year and Week yyyy-ww which starts at week "0".
A B C D E
1 2022-00 2022-01 2022-02 ... 2023-00
How do I convert to a "Date Range" like this in Google Sheets?
A B C D E
1 Dec 26 - Jan 1 2 Jan - 8 Jan 9 Jan - 15 Jan ... ...
I'm not sure if this is what you are looking for but this is a math formula that gets you your results. Paste it in A2 and it will spill over through all the columns.
=ARRAYFORMULA(IF(A1:1<>"",TEXT(DATE(LEFT(A1:1,4),1,1)+(7*RIGHT(A1:1,2)-6),"mmm dd")&" - "&TEXT(DATE(LEFT(A1:1,4),1,1)+(7*RIGHT(A1:1,2)),"mmm dd"),""))
You could then copy and paste the values over your original row. Assuming you want to convert your current format over to this new format permanently.
If you are looking for a way to literally format the cell, I do not believe that is possible from a yyyy-ww format.
UPDATE:
If curious, a shorter version using LAMBDA would look like:
=ARRAYFORMULA(LAMBDA(a,IF(a>0,TEXT(a,"mmm dd")&" - "&TEXT(a+6,"mmm dd"),""))(DATE(LEFT(A1:1,4),1,1)+(7*RIGHT(A1:1,2)-6)))
can you try this out:
=BYCOL(A1:G1,LAMBDA(ax,LAMBDA(s,w,LAMBDA(z,iz,IFS(iz=1,text(MAX(z)-6,"MMM D")&" - "&text(MAX(z),"MMM D"),iz=53,text(MIN(z),"MMM D")&" - "&text(MIN(z)+6,"MMM D"),(iz<>1)+(iz<>53),text(MIN(z),"D MMM")&" - "&text(MAX(z),"D MMM")))(FILTER(s,w=--RIGHT(ax,2)+1,YEAR(s)=--LEFT(ax,4)),FILTER({w},w=--RIGHT(ax,2)+1,YEAR(s)=--LEFT(ax,4))))(SEQUENCE(DAYS("12/31/2025", "1/1/2020")+1,1,DATE(2020,1,1)),INDEX(WEEKNUM(SEQUENCE(DAYS("12/31/2025", "1/1/2020")+1,1,DATE(2020,1,1)))))))
I have long (multiple thousand lines and growing) list of data in Sheets which have a date and additional columns with data. Here's a simplified example of this list (=TAB1):
Date Number Product-ID
02.09.2021 123 1
02.09.2021 2 1
01.09.2021 15 1
01.09.2021 675 2
01.09.2021 45 2
01.09.2021 52 1
31.08.2021 2 1
31.08.2021 78 1
31.08.2021 44 1
31.08.2021 964 2
30.08.2021 1 2
29.08.2021 ...
...
Three remarks:
The date is formatted to European standard DD.MM.YYYY
There definitely is more than one line per day per product (could be a big number depending on the day)
(for the formulas below) In the European standard Sheets uses ; instead of , as in =IF(A;B;C)
In a different tab (=TAB2), I want to add up all the numbers for a unique date for Product-ID 1. So far I've done it like this:
Date Sum (if Product-ID=1)
=UNIQUE('TAB1'!A2:A) =ARRAYFORMULA(SUMIF('TAB1'!A:A&'TAB1'!C:C;A2:A&"1";'TAB1'!B:B))
02.09.2021 125
01.09.2021 67
31.08.2021 124
30.08.2021 1
29.08.2021 ...
...
This works fine so far. Here's what I want to do now:
For every month (here: August and September 2021) I need an additional line above the current date (in this case: above 02.09.2021) AND above a completed month to sum over the whole month for column B. Here's how it should look like:
Date Sum (if Product-ID=1)
September 2021 192
02.09.2021 125
01.09.2021 67
August 2021 125
31.08.2021 124
30.08.2021 1
29.08.2021 ...
Of course, the line for the next day (03.09.2021) should be added above 02.09.2021 and below the sum for the month when it's automatically added to TAB1 on the next day.
I tried to play around with s.th. like =IF(DAY(UNIQUE('TAB1'!A2:A))=1;...;...) but didn't get far.
Is there anyone with an idea how to realize s.th. like this?
You want to learn about QUERY().
in cell A1 of an empty tab.
=QUERY('TAB1'!A2:C,"select A,SUM(B) where C = 1 group by A")
it makes a very big difference whether your product ids are text or numbers. the above was written as if they are numbers, but you might have just been simplifying. If they are text you would write it like this:
=QUERY('TAB1'!A2:C,"select A,SUM(B) where C = '1XYZ' group by A")
note the single quotes.
if the IDs are a MIX of text and letters then you need to force them all to text values in the original data by highlighting the IDs column and choosing Format>Number>Plain Text from the menu bar.
UPDATE:
I understand the requirements better now for intermixing a cumulative month total into the output. This may work.
=ARRAYFORMULA({QUERY({EOMONTH('TAB1'!A2:A,0),'TAB1'!B2:C},"select 'Total',Col1,SUM(Col2) where Col3 = 1 group by 'Total',Col1 label 'Total''',SUM(Col2)''",0);QUERY('TAB1'!A2:C,"select '',A,SUM(B) where C = 1 group by '',A label '''',SUM(B)''",0)},"order by Col2,Col1",0))
This question already has answers here:
How to SUM duration in Google Sheets?
(5 answers)
Closed 1 year ago.
I have time values above 24 hours in one column and need to calculate a sum, but it's tricky. I tried using this formula
=ARRAYFORMULA(TEXT(SUM(IFERROR(TIMEVALUE(K2:INDIRECT(CONCAT("K", ROW()-1))))), "[hh]:mm"))
the time values are in column K
Also I tried using Query function
=Query({A1:K,{"Duration";ArrayFormula(if(len(K2:K),(hour(K2:K)/24+minute(K2:K)/1440),))}},"Select Sum(Col12)",1)
Result is same for both formulas. Here's the problem. Each 24 hours of each time value resets to 0 when calculating. Let's say the values are 12:00, 12:00, 23:00 then the sum is 47:00 which is OK. but when the values are 12:00, 12:00, 24:00 then 24 turns to 0 and the sum is 24:00. If the values are 12:00, 12:00, 25:00 then then 25 turns to 1 and the sum is 25:00. Same is when the values are 12:00, 12:00 and 49:00 as 49 is 24+24+1 so it turns to 1:00
try:
=ARRAYFORMULA(TEXT(SUM(IFERROR(VALUE(TO_TEXT(INDIRECT("A1:A"&ROW()-1))))), "[h]:mm"))
I have a workbook where I track game stats for my local community. I added a chart that changes upon a few selections and I use filter to get the desired result. The data comes from a sheet where I use query to calculate month to month differences (since I could not find this easily done with google's provided pivot options). One of the query's looks like this
=query('Response Edits'!1:1112,"select A,B,C WHERE A IS NOT NULL AND NOT H matches '"&textjoin("|",TRUE,query('Response Edits'!1:1112,"select min(H) WHERE A IS NOT NULL group by D",0))&"' order by D, C ASC",0)
A converts the month value in the timestamp to the correct survey month (e.g. a 2020-07-01 would be for 06 survey and 2020-07-29 would
be for 07 survey)
B converts the year value in the timestamp to the correct survey year
C is the timestamp of the survey submission
D is the player name
H is the player XP of the survey submission (I use this as a lazy solution since it only increases and because I could not figure out a
way to include the key phrase date using multiple datetime e.g.
NOT C matches date texjoin("|",TRUE,"select min(C)...") did not work)
the textjoin is just to remove the earliest date submitted because it would not have a month to month value. Here is a portion of the output of the query above and another query which I believe is correct:
7 2020 2020-07-31 23:18:48 ... 6873449 198 11610
8 2020 2020-08-31 22:15:53 ... 7789713 175 8732
9 2020 2020-09-30 23:03:12 ... 5994347 139 8932
When I close the the sheet and reopen it I notice that my chart has only 0 values because my sheet with the query functions is only outputting 0. The above query and my other query have also given a different output, which I have provided a portion for below:
6 2020 2020-06-30 22:04:02 ... 0 0 0
7 2020 2020-07-31 23:18:48 ... 0 0 0
8 2020 2020-08-31 22:15:53 ... 0 0 0
9 2020 2020-09-30 23:03:12 ... 0 0 0
I am new to using query, but the formula seems correct, because if I change the last 0 in the formula (which is the option for header) to 1 and then back to 0 I get the desired result.
Tl;dr Why does the queried data not output correctly when I close and reopen a workbook? And why does it output correctly after the formula is changed and changed back (including selecting undo)? Is it potentially textjoin or matches causing the problem in the query?
try to run this:
=QUERY('Response Edits'!A1:H1112,
"select A,B,C
where A is not null
and not H matches '"&TEXTJOIN("|", 1,
QUERY('Response Edits'!A1:H1112,
"select min(H)
where A is not null group by D", 0))&"'
order by D, C", 0)
can it be that Google Sheets is not calculating right?
=DAYS360(DATE(2016;12;31); date(2017;1;1))
is 1 and also this is 1 but is should be 2:
=DAYS360(DATE(2016;12;30); date(2017;1;1))
Whats wrong here?
I think it is because of the formula that is set to 360 days. It is said here that DAYS360 - Days between two dates on a 360-day year. So it means that you will only have a 30 days a month not including the date 31 in the months of (Jan, March, May, July, Aug, Oct and Dec).
For example, you use this =DAYS360(DATE(2016,10,25), date(2016,10,30)) so the expected output is 5 - which is correct
If you use =DAYS360(DATE(2016,10,25), date(2016,10,31)) the expected output is 6 - because you specify the date 31.
But, if you use =DAYS360(DATE(2016,10,25), date(2016,11,3)), the output is 8 not 9 - because it did not include the date 31.
I hope I explained it clearly.