I have a Google Sheet (Test Sheet 2) with two sheets in it, Sheet 1 and Sheet 2. Sheet 2 is where all of the data is and I need to get the sums of the counts of that column based on three criteria into sheet 1 column C. The name, week, year and count need to match up. I used the formula
=arrayformula(iferror(vlookup(A2:A&2020&B2:B, {Sheet2!A2:A&Sheet2!B2:B&Sheet2!C2:C, Sheet2!D2:D}, 2, FALSE)))
but that only works for unique rows. In the example sheet I am providing, the formula works well for Bill, Lisa, Katie and Jon because they all have one value for 'count' from Sheet2 when the parameters of name, week and year match up. But Mike has two rows matching the criteria. This formula returns the first match which is 3. The other value is 4 so I would like the count in Sheet1 to show 7 instead of 3. I need it to add them up.
I also tried to use sumifs but the columns are two different sizes so that didn't work.
Any idea? I did try to combine sumif with the above formula but that did not work either.
Link to Test Sheet
Solution with ARRAYFORMULA and SUMIF
If you need to use ARRAYFORMULA to improve the performances you can use this tweak of the SUMIF statement: basically you can concatenate the conditions to make them create a single AND condition.
This would be a possible solution for the formula in your comment:
=ARRAYFORMULA(SUMIF(Sheet2!A2:A&Sheet2!B2:B,A2:A&2020,Sheet2!D2:D))
Solution with SUMIFS
If you are looking for a solution with the SUMIFS formula you can use this:
SUMIFS('sum_range', 'criteria_range', condition, ['criteria_range_2', condition_2])
In your case this will translate to:
=SUMIFS(Sheet2!D2:D, Sheet2!A2:A, A2, Sheet2!B2:B, 2020)
In this case the ranges dimensions won't affect the formula execution.
Just drag this formula for the Sheet1 table column and you will get the results. The drawback is that you cannot use ARRAYFORMULA with SUMIFS. Performance wise, if you have a lot of rows in the Sheet1 I suggest using the ARRAYFORMULA solution, since this will trigger a lot of formula calls instead of just one.
Try this query()
=query(Sheet2!A:D, "Select A, C, sum(D) where B = 2020 group by A, C label C 'Week', sum(D) 'Count'", 1)
UPDATED:
If you really need to use vlookup in arrayformula() you can always ise the query (that deals with the summing) as the lookup range. In the spreadsheet I used
=ArrayFormula(if(len(A2:A), iferror(vlookup(A2:A&year(D2:D)&E2:E, query({Sheet2!A:A&Sheet2!B:B&Sheet2!C:C, Sheet2!D:D}, "Select Col1, sum(Col2) where Col1 <>'' group by Col1", 1), 2, 0)),) )
and see if that helps?
Related
This might be something fairly simple but struggling to find a way to do it.
In Column B, I have a list of foods required.
In Column C, I have the amount needed.
In Column D, I have g (for grams) ml (for mills) etc.
I would like to combine the duplicates in Column B and update the totals from Column C, with the g or ml in Column D beside it.
The list I have has been created by using an array formula based on dropdowns in another sheet.
I have seen people using UNIQUE formula in 1 column (this works) and then a SUMIF formula in another column and then a JOIN formula in another... I tried this but the SUMIF is always returning 0.
Would someone please be able to advise on how I can do this?
TIA :D
It's hard to be sure exactly what you need without seeing the data. But based on my understanding of solely what you've posted, this QUERY formula should generate a condensed mini-report:
=QUERY({B2:D},"Select Col1, SUM(Col2), Col3 WHERE Col1 Is Not Null GROUP BY Col1, Col3 LABEL SUM(Col2) ''")
In plain English, this means "Arrange the data from the range B2:D in the same order as the raw data, but sum the second column's data according to matches in both the first and third columns. Only return results for the raw data where the first column is not blank. Replace the default 'sum' header on the second column with nothing; I don't need it."
This formula assumes that every ingredient will always be attached to the same measurement (e.g., 'salt' in Col B is always paired with 'mg' in Col D, etc.). If this is not the case, you will wind up with ingredients being listed as many times as there are different measures in Col D.
I have a problem with summing up my values from a data set, that's structured like this:
The goal is to sum the revenues separated by company and split by month, so the result is output in this way
I have tried it with some =sumifs + index/match and =sumproduct solutions, but can't seem to make it work.
Here's the sample file:
https://docs.google.com/spreadsheets/d/16xOoPCHDtcSRRojCkwcBorUc5dstgkXFPR6M_d5uY2U/edit#gid=0
On the "revenues" tab, in cell B4, try using the formula:
=SUMIFS(indirect(address(1,match(A4,Overview!$3:$3,0)-1,,,"Overview")&":"&address(1000,match(A4,Overview!$3:$3,0)-1)),Overview!A1:A1000,">="&B$2,Overview!A1:A1000,"<="&B$3)
To break it down, this bit helps figure out which revenue column to use by matching the name of the company and then taking the column before that:
match(A4,Overview!$3:$3,0)-1
This bit creates an address "Overview!$G$1":
address(1,match(A4,Overview!$3:$3,0)-1,,,"Overview")
This bit creates the 2nd part of the address i.e.":$G$1000":
"&":"&address(1000,match(A4,Overview!$3:$3,0)-1)
And the rest is a SUMIFS where it sums the revenue column for dates after the 1st of the month and before the last date of the month.
Be careful: your data is for 2020 and your summary table is using dates in 2021.
Reference:
SUMIFS
ADDRESS
MATCH
INDIRECT
use in A4:
=ARRAYFORMULA(QUERY(QUERY({SPLIT(FLATTEN(IF(
FILTER(Overview!G7:1000, MOD(COLUMN(Overview!G7:1000)+2, 3)=0)="",,
TEXT(Overview!A7:A25, "m")&"×"&
FILTER(Overview!G7:1000, MOD(COLUMN(Overview!G7:1000)+2, 3)=0)&"×"&
FILTER(Overview!G3:3, MOD(COLUMN(Overview!G3:3)+1, 3)=0))), "×");
SEQUENCE(12), SEQUENCE(12, 2,,)},
"select Col3,sum(Col2)
where Col1 is not null
group by Col3
pivot Col1", 0),
"offset 2", 0))
I have two sheets. I'm using SUMPRODUCT to sum a column based on a matching string.
=SUMPRODUCT(--(skus_campaign!A:A=A2),skus_campaign!D:D)))
This works exactly as expected, if I drag the formula to the rows below.
If I attach ARRAYFORMULA and and IF test to see if there's a blank value, it won't work.
=ARRAYFORMULA(IF(ISBLANK(A2:A), " ", SUMPRODUCT(--(skus_campaign!A:A=A2),skus_campaign!D:D)))
Am I missing something here? Is there an easier way to accomplish this while still using ARRAYFORMULA to grow and shrink the column based on the values in column A?
EDIT: Here's the link to the example Google Sheet. Column "D" under the "Data" sheet is the issue.
Try in E1
={"COGS"; ArrayFormula(if(len(A2:A), vlookup(A2:A, query(skus!A:D, "Select A, sum(D) where A <>'' group by A"), 2, 0),))}
and see if that produces the desired result. If it does, clear all values and formulas in column D and enter the formula in D1.
I have a spreadsheet with 2 sheets in it,
I want to summarize the daily results by date.
I'm trying to use the query sum function to summarize everything since I wasn't able to do it with arrayformula.
but I'm not able to do it with a query as well.
I don't want to just copy-paste the sum function from each row to the next I want to just type the date I need in column A and get all the results in the different columns.
https://docs.google.com/spreadsheets/d/1ZsKXw32ycO_5KGD2I-Ug_GmqSIB_Z-D3Z1jlGd6fpTE/edit?usp=sharing
link to sheets.
getting the data from the database sheet.
I want to display the data-oriented by date and sumed.
for just 1 row you can simply do this and then drag down:
=ARRAYFORMULA(QUERY({TO_TEXT(DataBase!A:A), DataBase!B:E},
"select sum(Col5)
where Col1 = '"&TO_TEXT(A2)&"'
label sum(Col5)''", 0))
if array is needed then use:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, QUERY(DataBase!A:E,
"select A,sum(E)
where A is not null
group by A
label sum(E)''", 0), 2, 0)))
I have a spreadsheet with 2 sheets in it, I want to summarize the weekly results by date. I'm trying to use the query sum function to summarize everything since I wasn't able to do it with arrayformula.
but I'm not able to do it with a query as well. I don't want to just copy-paste the sum function from each row to the next I want to just type the date I need in column A and get all the results in the different columns.
https://docs.google.com/spreadsheets/d/1ZsKXw32ycO_5KGD2I-Ug_GmqSIB_Z-D3Z1jlGd6fpTE/edit?usp=sharing
link to sheets.
getting the data from the database sheet. I want to display the data-oriented by date and summed.
=ArrayFormula(IFERROR(FILTER(QUERY(DataBase!A2:E,"select A,sum(E)
where A is not null
group by A
label sum(E)''"), WEEKNUM(DataBase!A2:A)=WEEKNUM(A2:A))
))
I tried this formula and it dosent work..
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A,
QUERY(FILTER(DataBase!A2:E,WEEKNUM(DataBase!A2:A)=WEEKNUM(A2)),
"select Col1,sum(Col5)
where Col1 is not null
group by Col1
label sum(Col5)''"), 2, 0)))