How to calculate numbers of quarters between two dates in google sheets? - google-sheets

I am trying to determine the number of quarters between two dates in google sheets with Q1 being Jan 1 2022 to March 31 2022 & so on for Q2, Q3, Q4.
For example: Date1: 06/14/2022 & Date2: 10/12/2022, the result should be 3 i.e., Q2, Q3, Q4.
Any advise on how this can be achieved.
I tried something like below but doesnt work
=CEILING(((YEAR(V3)*12+MONTH(V3))-(YEAR(U3)*12+MONTH(U3)))/3)

For a simple one in the same year, try
=int((month(V3)-1)/3)-int((month(U3)-1)/3)+1
or
=QUOTIENT(month(V3)-1,3)-quotient(month(U3)-1,3)+1

try:
=ARRAYFORMULA(TRANSPOSE(QUERY(QUERY(SPLIT(FLATTEN(ROW(A1:A10)&"×"&IFNA(VLOOKUP(
IF(SEQUENCE(1, 1000, 0)<=DAYS(B1:B10, A1:A10), A1:A10+SEQUENCE(1, 1000, 0), ),
SPLIT(FLATTEN({"1/1/", "1/4/", "1/7/", "1/10/"}&
SEQUENCE(4, 1, 2020)&"×"&{"Q1","Q2","Q3","Q4"}), "×"), 2, 1))), "×"),
"select max(Col2) where Col2 is not null group by Col2 pivot Col1"), "offset 1", 0)))

Related

how to count values, if they fall under a separate category and within a group

Columns D:H show my initial info, where two workstreams (Column D) have different issues occur (Column F:H). These issues fall under one of three categories, under Columns A:B. I want the chart to show the count of the category each issues falls under, making sure it's also showing that it's within a certain workstream.
what i was working with so far is below to match issues to the three categories
=INDEX(A:B, MATCH(F1, A:A, 0), 2)
and below to count the times a value is within the workstream group (A or B).
=countif(flatten(filter(F:H,D:D="A")),"one")
How can I combine these two?
https://docs.google.com/spreadsheets/d/1hs-Srt-qdOR44V_rmvKF-rC5DThRrQrrCfiA_jAvnH0/edit?usp=sharing
delete J:M range and use in D1:
=INDEX({QUERY(SPLIT(FLATTEN(D1:D9&"×"&VLOOKUP(F1:H9, A1:B12, 2, 0)), "×"),
"select Col1,count(Col1) where Col2 is not null
group by Col1 pivot Col2 label Col1'workstream'"); "TOTAL",
TRANSPOSE(MMULT(1*QUERY(
QUERY(SPLIT(FLATTEN(D1:D9&"×"&VLOOKUP(F1:H9, A1:B12, 2, 0)), "×"),
"select count(Col2) where Col2 is not null
group by Col2 pivot Col1"), "offset 1", ),
SEQUENCE(COUNTUNIQUE(D1:D9), 1, 1, 0)))})
formula explanation

Returning top value of column from range in google sheets

Say I had a list like this.
Group 1 Group 2
Edward, C Kate, A
Mark, F Ava, Z
Now, in a different column =IF(COUNTIF('Gender'!$A$2:$B$3, "Kate, A"), "", "") is my current formula. I would like to make the first set of empty speech marks return Group 1 or Group 2 depending what column it is. I still require the COUNTIF because my actual sheet has values which will not be contained in either column.
Thanks.
try:
=INDEX(IFNA(VLOOKUP("Kate, A", SPLIT(FLATTEN(
IF(Gender!A2:B="",,Gender!A2:B&"×"&Gender!A1:B1)), "×"), 2, 0)))
update:
=INDEX(IFNA(VLOOKUP(A1:A, QUERY(SPLIT(FLATTEN(
IF(Groups!B2:C="",,Groups!B2:C&"×"&Groups!A1&"×"&Groups!B1:C1),
IF(Groups!F2:G="",,Groups!F2:G&"×"&Groups!E1&"×"&Groups!F1:G1)), "×"),
"select Col1,max(Col3) where Col2 is not null
group by Col1 pivot Col2 label Col1'"&A1&"'"), {2, 3}, 0)))
demo sheet

How to find moving average/max/min of specific period in an array in google sheet

I have a google sheet with following data. I have to find moving average of 14(any period) period. It can be found by copy and pasting average function But I want to find it in an array.
Anyone's help is appreciated.
This is a simpler approach that might work for you:
=ArrayFormula(if(A2:A="","",(sumif(row(A2:A),"<"&row(A2:A)+14,A2:A)-sumif(row(A2:A),"<"&row(A2:A),A2:A))
/countifs(row(A2:A),">="&row(A2:A),row(A2:A),"<"&row(A2:A)+14,A2:A,"<>")))
The running average uses a diminishing range at the end of the data.
avg:
=INDEX(IFNA(VLOOKUP(ROW(A1:A),
QUERY(SPLIT(FLATTEN(ROW(A1:A)&"×"&ARRAY_CONSTRAIN(
SPLIT(FLATTEN(QUERY(TRANSPOSE(IF(ROW(A1:A)<=TRANSPOSE(ROW(A1:A))=TRUE,
TRANSPOSE(A1:A*1)&"×", )),,9^9)), "×"), 9^9, 14 +N("14 day window"))), "×"),
"select Col1,avg(Col2)
where Col2 is not null
group by Col1"), 2, )))
max:
=INDEX(IFNA(VLOOKUP(ROW(A1:A),
QUERY(SPLIT(FLATTEN(ROW(A1:A)&"×"&ARRAY_CONSTRAIN(
SPLIT(FLATTEN(QUERY(TRANSPOSE(IF(ROW(A1:A)<=TRANSPOSE(ROW(A1:A))=TRUE,
TRANSPOSE(A1:A)&"×", )),,9^9)), "×"), 9^9, 14 +N("14 day window"))), "×"),
"select Col1,max(Col2)
where Col2 is not null
group by Col1"), 2, )))
min:
=INDEX(IFNA(VLOOKUP(ROW(A1:A),
QUERY(SPLIT(FLATTEN(ROW(A1:A)&"×"&ARRAY_CONSTRAIN(
SPLIT(FLATTEN(QUERY(TRANSPOSE(IF(ROW(A1:A)<=TRANSPOSE(ROW(A1:A))=TRUE,
TRANSPOSE(A1:A)&"×", )),,9^9)), "×"), 9^9, 14 +N("14 day window"))), "×"),
"select Col1,min(Col2)
where Col2 is not null
group by Col1"), 2, )))

How can I get a QUERY to CONCATENATE text after it combines data?

On this sheet, I've been working on I have the info I need adjusting down into the Query Results
=QUERY(Investors!A4:D,
"select B,C,sum(D)
where B is not null
group by B,C
label sum(D)''")
How do I get the Stock Numbers Due that day to be listed out in column D? Like this:
1. 10/7/2019 Grady Johnson $100.12 PT-1013
2. 11/15/2020 Bill Jones $553.80 PT-1020, PT-1019
3. 11/15/2020 Grady Johnson $45.00 PT-1011
4. 11/15/2020 Steve Robinson $320.00 PT-1018, PT-1016
5. 11/17/2020 Jim Luke $1,057.20 PT-1009, PT-1008, PT-1007, PT-1006
6. 11/22/2020 Jim Luke $300.43 PT-1010
Here's the link: Google Sheet
Any help is appreciated!
or paste this in row 3 and drag down:
=JOIN(", ", IFNA(FILTER(Investors!A$4:A, Investors!B$4:B&" "&Investors!C$4:C=A3&" "&B3)))
try:
=ARRAYFORMULA(REGEXREPLACE(IFNA(VLOOKUP(TO_TEXT(A3:A)&" "&B3:B,
TRIM({TRANSPOSE(QUERY(TRANSPOSE(QUERY(QUERY({Investors!A4:C},
"select Col2,Col3,count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"select Col1,Col2 offset 1", 0)),,9^9)),
TRANSPOSE(QUERY(TRANSPOSE(IF(QUERY(QUERY({Investors!A4:C},
"select count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"offset 1", 0)="",,
QUERY(QUERY({Investors!A4:A&",", Investors!B4:C},
"select count(Col2) where Col2 is not null group by Col2,Col3 pivot Col1"),
"limit 0", 1))),,9^9))}), 2, 0)), ",$", ))
Here is my suggested formula to be placed in Combined!D3 of your sample spreadsheet:
=ArrayFormula(IF(A3:A="",,SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(VLOOKUP(TRANSPOSE(FILTER(Investors!A4:A,Investors!A4:A<>"")),{Investors!A:A,Investors!C:C&Investors!B:B},2,FALSE)=B3:B&A3:A,TRANSPOSE(FILTER(Investors!A4:A,Investors!A4:A<>"")),))," ",COUNTA(Investors!A4:A))))," ",", ")))
As for how it works, that would be time-consuming to explain. (More time than is reasonable for a free site such as this.) I will suggest that, if this is important to you, take the time to study it. Take it apart and see what each piece does — separately and then in combination with other parts — until you've gotten it all back together.

How to sum all value based on multiple data input in one cell

I have a sheet like this
A B C D
Apple 10 Apple Apple Orange Melon
Orange 30
Melon 50
I want D1 to show the sum value based on the value in C1 which is 2 apples, oranges, and Melon (10+10+30+50) = 100
Any advice on what to type in column D1? I assume it will be related to sumif?
=ARRAYFORMULA(SUMPRODUCT(QUERY({A1:B, IFERROR(VLOOKUP(A1:A,
QUERY(TRANSPOSE(SPLIT(C1, " ")),
"select Col1,count(Col1) group by Col1", 0), 2, 0))},
"select Col2*Col3")))
In addition to the previous formula, this should probably also work:
=sum(ArrayFormula(iferror(vlookup(split(C1, " "), A1:B, 2, 0))))

Resources