How to make ARRAYFORMULA work with SUMIFS? - google-sheets

I have a SUMIFS formula that works fine, but I have to drag it down to populate every column, which is quite impractical for the amount of data I have in my spreadsheet, therefore I want to turn it into an ARRAYFORMULA. The formula is supposed to calculate how many of a product was purchased in a month. It currently looks like this:
=SUMIFS(All!$N$3:$N, All!$AG$3:$AG, ">=1/1/2018", All!$AG$3:$AG, "<=31/1/2018", All!$L$3:$L, $A2)
All!N contains the quantity of an item the customer purchased, All!AG contains the date, and All!L contains the product code which is checked against the product code in column A.
I tried simply doing
=ARRAYFORMULA(SUMIFS(All!$N$3:$N, All!$AG$3:$AG, ">=1/1/2018", All!$AG$3:$AG, "<=31/1/2018", All!$L$3:$L, $A$2:$A))
but that only works for cell A2 - it just prints the same result as the other formula and doesn't carry on down the column, which is what I want it to do. That solution worked with a SUMIF formula I have (it does the same thing but doesn't check the date) but it won't work with SUMIFS. I'm not sure why and I'm not the best at troubleshooting these spreadsheet formulas so I'm hoping someone can help.
Update: Here is a dummy sheet showing the issue: https://docs.google.com/spreadsheets/d/1pX-icbJxmy8A0jhKLnSRxhZTLRgYFG_iU2BOQrseCCg/edit?usp=sharing

paste in B2 cell:
=ARRAYFORMULA(IF(LEN($A$2:$A), IFERROR(VLOOKUP($A$2:$A,
QUERY({All!$B$3:$D},
"select Col1, sum(Col2)
where Col3 is not null
group by Col1
label sum(Col2)''", 0), 2, 0), 0), ))
paste in C2 cell and drag to the right:
=ARRAYFORMULA(IF(LEN($A$2:$A), IFERROR(VLOOKUP($A$2:$A,
QUERY({All!$B$3:$D},
"select Col1, sum(Col2)
where Col3 >= date '"&TEXT( C$1, "yyyy-mm-dd")&"'
and Col3 <= date '"&TEXT(EOMONTH(C$1, 0), "yyyy-mm-dd")&"'
group by Col1
label sum(Col2)''", 0), 2, 0), 0), ))
spreadsheet demo

Related

Why isn't the array formula applying to the entire column?

I have a formula in cells F1 and G1 of this sheet. I want to keep the text that is in cells F/G8 and F9&G9 however it's giving me an error. Note that the formula is in an array so that it can apply retroactively to all of the cells in the column.
Here is the code used in Cell F1:
=ARRAYFORMULA(IFNA(VLOOKUP(B2:B, QUERY('Raw Logs'!C2:F, "select C,sum(F) group by C label sum(F)''"), 4, 0)))
Here is the code used in Cell G1:
=ARRAYFORMULA(IFNA(VLOOKUP(B2:B, QUERY('Raw Logs'!C2:H, "select C,sum(H) group by C label sum(H)''"), 6, 0)))
Additionally, the data from the formula in Cell C1 is no longer populating (it was before) - the error says it can't because it's unable to overwrite C9 however there was text in C9 earlier and the data from the formula was still populating.
Here's the formula used in Cell C1:
=ArrayFormula(IFERROR(VLOOKUP(B:B,'Roster Registrations'!F1:G,2,FALSE)))
Any tips on how I can resolve this?
array formula needs a space to roll out - that's why. if you want to run it from that 1st row delete cells F8:F9 and use:
={"";"";"";"";"";"";"";"Total for February";
"Activity"&CHAR(10)&"Hours"; "";
ARRAYFORMULA(IFNA(VLOOKUP(B11:B&"", TEXT(QUERY('Raw Logs'!C2:F*1,
"select Col1,sum(Col4)
where Col1 is not null
group by Col1
label sum(Col4)''"), {"#", "[h]:mm:ss"}), 2, 0)))}
for G1 fx delete G9 and use this in G1:
={"";"";"";"";"";"";"";"";
"Number of"&CHAR(10)&"Tests"; "";
ARRAYFORMULA(IFNA(VLOOKUP(B11:B, QUERY('Raw Logs'!C2:H*1,
"select Col1,sum(Col6)
where Col1 is not null
and Col1 <> 0
group by Col1
label sum(Col6)''"), 2, 0)))}

Apply array formula to sumifs

I have Google sheet with sum-ifs functions, but I need to make it apply to the whole columns instead of just one cell and to apply automatically to new rows when there added
I know that arrays don't work with sumifs after doing research but I can't seem to figure out to apply an array function to this.
=ArrayFormula(SUMIFS(K:K,C:C,C2,L:L,false))
so I tried instead to make it a =sum(if(and function instead with an array, but couldn't get that to work either. not sure how to get it to apply to the same affect as the above formula
I need to apply the following sum-ifs all the conditions are met to each cell in the selected column
basically like this:
=QUERY({C2:C, K2:L},
"select Col1,sum(Col2)
where Col1 is not null
and Col3 = FALSE
group by Col1
label sum(Col2)''", 0)
if you want to pair it with list of names then use VLOOKUP:
=ARRAYFORMULA(IFERROR(VLOOKUP(C2:C, QUERY({C2:C, K2:L},
"select Col1,sum(Col2)
where Col1 is not null
and Col3 = FALSE
group by Col1
label sum(Col2)''", 0), 2, 0)))

How to use Averageifs or Sumifs in an Arrayformula

I'll post a link to the spreadsheet at the bottom of this write-up.
I'm trying to work out the average of a column of numbers that fall between a date range. The formula below works but I have to drag it down the column, I want it to be an array so it auto updates.
=iferror(averageifs(B$2:B,A$2:A,">="&C2,A$2:A,"<="&D2),1)
So I created it as an array as follows:
=iferror(ArrayFormula(averageifs(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1
But it stops after the first cell. So I broke up the average function into sum & count in order to divide.
The count array works using this formula:
=iferror(ArrayFormula(countifs(A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1)
However the sum array does not even go past the first cell:
=iferror(ArrayFormula(SUMIFS(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)),1)
And the combination gets past the first cell but the calculations all come to zero:
=ArrayFormula(iferror(SUMIFS(B$2:B,A$2:A,">="&C2:C,A$2:A,"<="&D2:D)/countifs(A$2:A,">="&C2:C,A$2:A,"<="&D2:D),1))
What I'm trying to achieve is an average for the previous month.
If anyone can help me I'd be very grateful!
https://docs.google.com/spreadsheets/d/1XhoLl5hB-MpXFz9VS2aLqJOWbXk1d_7apnwKWFdDUlg/edit?usp=sharing
you are trying to apply a bit weird structural logic with lots of repeating values with no reason. basically, it looks like you need this:
=ARRAYFORMULA(QUERY({TEXT(A2:A, "yyyy-mmm"), B2:B},
"select Col1,avg(Col2)
where Col2 is not null
group by Col1
order by avg(Col2) desc
label avg(Col2)''", 0))
but if you really really need so:
=ARRAYFORMULA(IF(LEN(A2:A),
IFERROR(VLOOKUP(TEXT(DATE(YEAR(A2:A), MONTH(A2:A)-1, 1), "yyyy-mmm"),
QUERY({TEXT(A2:A, "yyyy-mmm"), B2:B},
"select Col1,avg(Col2)
where Col2 is not null
group by Col1", 0), 2, 0), 0), ))

Is it possible to get a particular row cell value using a formula that combines both row and column searches?

I am setting up a shift roster. The top row is sequential dates, and the leftmost rows are staff names. A staff member can look along their row to see which shifts they are on for the coming weeks.
I want to automatically pull out the allocated shifts into another sheet to show a dynamic "Today's Staffing" which shows who is on duty in each role for the day e.g. for column TODAY'S DATE find which row contains MORNING SHIFT and return the FIRST COLUMN FOR THAT ROW which should contain the name.
I have access to both MS Excel and Google Sheets.
Is there a function/way that I can do this?
Example google sheet:
https://docs.google.com/spreadsheets/d/1VTYK39xuHT0-4s8O5398dnseXYsE0q54-os-rJNNVB8/edit?usp=sharing
=QUERY({INDIRECT(ADDRESS(2, MATCH(TODAY(), A1:1, 0), 4)&":"&
SUBSTITUTE(ADDRESS(1, MATCH(TODAY(), A1:1, 0), 4), 1, )), A2:A},
"where Col1 <>'OFF' and Col1 <>''")
if you want to run this under with just 3 people do:
=QUERY({INDIRECT(ADDRESS(2, MATCH(TODAY(), Sheet1!A1:1, 0), 4)&":"&
SUBSTITUTE(ADDRESS(4, MATCH(TODAY(), Sheet1!A1:1, 0), 4), 1, )), Sheet1!A2:A4},
"where Col1 <>'OFF' and Col1 <>'' order by Col1 desc")

Is there a reason why my ArrayFormula is not working in the other cells of my column?

In a Google sheet with form responses, I made an additional column where I want to look up from each submission if the value left of my new column already occurs in a range on another sheet.
So this is going to be a Vlookup formula finally.
Unfortunately, I didn't make it to the Vlookup part yet because the ArrayFormula part is not working.
I started off by looking to the cell value at the left with this formula, which worked, but the ArrayFormula part of it DOESN'T work.
=ArrayFormula(indirect(ADDRESS(ROW(), COLUMN()-1)))
I know that some functions don't work very well with ArrayFormula,
But I don't see any reason here this should not work because it's only looking to its row and its column.
I hope the image shows the problem well enough
If you just want to repeat the values from the previous column (let's say column A, starting in row 2), you can try in column B (also in row 2)
=Arrayformula(if(len(A2:A), A2:A,))
Change range to suit. See if that helps?
UPDATE: To repeat the previous column (anywhere you input the formula) try (in row 2)
=offset(A1, 1, column()-2, rows(A1:A))
To 'limit' the output you can use any number instead of rows(A1:A) or replace it with COUNTA(A1:A)...
you can do something like this, which will search for specific header across entire sheet and then return values of that column:
=QUERY({INDIRECT("Sheet1!"&
ADDRESS(1, MATCH("job ID", Sheet1!1:1, 0), 4)&":"&
ADDRESS(1000000, MATCH("job ID", Sheet1!1:1, 0), 4))},
"select * where not Col1 matches 'job ID' and Col1 is not NULL", 0)
without sheet name:
=QUERY({INDIRECT(
ADDRESS(1, MATCH("job ID", 1:1, 0), 4)&":"&
ADDRESS(1000000, MATCH("job ID", 1:1, 0), 4))},
"select * where not Col1 matches 'job ID' and Col1 is not NULL", 0)

Resources