I have a Query formula in Google Sheets where I'm trying to set a condition that shows rows where Col1 > (Col2 +15 days). I'm not sure how to do the math on the +15 days in the Query formula.
I tried the following code:
=Query(A:B,"Select * where Col1>Col2+15")
I want it to show me where Column 1 is greater than the Col2 date + 15 days
Or you can use Datediff within your query:
=Query(A:B,"Select * where A is not null and datediff(A,B)>15")
See
I would add into the query {A:B,B:B+15}. This will add a third column into your selection with Col2+15 days. Then from there, you can select the first two columns, but still ask whether Col1 is greater than Col3.
=arrayformula(query({A:B,B:B+15},"select Col1,Col2 where Col1 > Col3"))
=ARRAYFORMULA(TO_DATE(QUERY(VALUE(A1:B),
"select * where Col1 > Col2+15", 0)))
Related
Hello, please help me
How to split sum by month? in googlesheets ?
Try:
Formula in J3:
=INDEX(QUERY({TEXT(B3:B,"YYYY-MM"),H3:H},"Select Col1, sum(Col2) where Col2>0 group by Col1 label Col1 'month'"))
Use this formula
= ArrayFormula(
{ TEXT(DATE(YEAR(TODAY());UNIQUE(MONTH(A3:A));DAY(TODAY())); "mmmm yyyy")\ IF(SUMIF(MONTH(A3:A); UNIQUE(MONTH(A3:A));H3:H)=0;;TEXT(SUMIF(MONTH(A3:A); UNIQUE(MONTH(A3:A)); H3:H); "Rp#,###"))})
Formula:
=ARRAYFORMULA(SUMIF(MONTH(A3:A); UNIQUE(MONTH(A3:A)); H3:H))
Explanation:
MONTH(A3:A) extracts the month from the dates in column A
UNIQUE(MONTH(A3:A)) finds the unique months from this list
SUMIF() takes the month of each row as the range for the summation, the list of unique months as the criteria, and then the total values H3:H as the range to sum.
ARRAYFORMULA() expands it to all rows below
Use QUERY() function with date columns so that we can sort if needed. Use EOMONTH() to make group by month.
=QUERY({INDEX(IF(B2:B="",,EOMONTH(B2:B,0))),E2:E},"select Col1,sum(Col2)
where Col1 is not null
group by Col1
label Col1 'Month', sum(Col2) 'Total'
format Col1 'MMM-YYYY'")
I have two columns (see screenshot)
How can i create a formula that sum the second LATEST column values with a criteria from column A?
For example i need the sum of the last 6 values (from column B) of the cells (in column A) that start with HH, so values starting from the bottom.
I know how to make a sum of all values (from column B) containing HH (from column A)
=SUMIF(A1:A;"HH"&"*";B1:B)
P.S. HH and * are separate because i'll substitute the HH with a cell
but now i need to delimit this to the last N values (let say last 3 values)
P.P.S.
=SUMPRODUCT((COUNTIFS(A1:A;"exact text";ROW(A1:A)*{1;1};">="&ROW(A1:A)*{1;1})<=3)*(A1:A="exact text");B1:B)
This works so far ONLY if i write the exact text, not with values like HH*
Maybe try
=sum(index(query({row(A1:A), A1:B}, "Select Col3 where Col2 contains 'HH' order by Col1 desc limit 6")))
and see if that works?
Note:
*the string HH can be also be in a cell (ex. D1)
=sum(index(query({row(A1:A), A1:B}, "Select Col3 where Col2 contains '"&D1&"' order by Col1 desc limit 6")))
*6 indicates the number of values you want to sum
EDIT: For your locale you'll need to use in G1
=sum(index(query({row($B$1:$B) \ $B$1:$C}; "Select Col3 where Col2 contains '"&E2&"' order by Col1 desc limit 3")))
and fill down. See if that works?
This should also work, not sure if it's any easier to understand/ less complicated than any other approach:
=SUM(SORTN(REGEXMATCH(B:B;E2)*C:C;3;0;ROW(B:B)*REGEXMATCH(B:B;E2);0))
Note the number 3 for the number of values you want from the bottom. and the reference to E2, which is "HH" as on your sample sheet.
use:
=QUERY(FILTER({IFNA(REGEXEXTRACT(SORT(B2:B; ROW(B2:B); 0);
"^([A-Za-z]{1,3})\d"))\SORT(C2:C; ROW(B2:B); 0)}; COUNTIFS(
REGEXEXTRACT(SORT(B2:B; ROW(B2:B); 0); "^([A-Za-z]{1,3})\d");
REGEXEXTRACT(SORT(B2:B; ROW(B2:B); 0); "^([A-Za-z]{1,3})\d");
ROW(H2:H43); "<="&ROW(H2:H43))<=3);
"select Col1,sum(Col2) group by Col1 label sum(Col2)''")
full explanation here
I want to make two columns one that has date and the other that has sum for the number of violations occurred on that day. Have a look at the data below.
use:
=QUERY({B:C}; "select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col1)''")
I have the following table:
What I'm trying to do is to write a formula that totals by each unique day in the month and year given in B1 and C1 thus the output should be:
I'm not sure how to start with this, googling seems to suggest the use of SUMIF.
Sheet is here
try:
=QUERY(FILTER({A5:B, TIMEVALUE(C5:C)}, MONTH(A5:A)=MONTH(B1&1), YEAR(A5:A)=D1),
"select Col1,sum(Col3)
where Col1 is not null
group by Col1
label sum(Col3)''
format sum(Col3)'[hh]:mm'", 0)
I have a spreadsheet that has data in one column (H2:H500) and dates in another column (F2:F500). I would like a sum of the total number in the past work week (Monday-Friday). I'm not sure if I need to use =CountIfs or what. Any help would be greatly appreciated!
=COUNTIFS(F2:F500,WEEKNUM(TODAY(),1),H2:H500, "<>")
...doesn't seem to work. Am I close?
=COUNTA(QUERY({A2:B},
"select Col1
where Col2 is not null
and Col1 >= date '"&TEXT(DATE(YEAR(TODAY()),1,1)-WEEKDAY(DATE(YEAR(TODAY()),1,1),3)+7*
(WEEKDAY(DATE(YEAR(TODAY()),1,1),3)>3)+7*(WEEKNUM(TODAY())-2),"yyyy-mm-dd")&"'
and Col1 <= date '"&TEXT(DATE(YEAR(TODAY()),1,1)-WEEKDAY(DATE(YEAR(TODAY()),1,1),3)+7*
(WEEKDAY(DATE(YEAR(TODAY()),1,1),3)>3)+7*(WEEKNUM(TODAY())-2)+4,"yyyy-mm-dd")&"'"))