How to use ranges in formulas with external sheet links - google-sheets

I'd like to use a SUMIF formula in one sheet that references a range in a separate sheet.
My problem is that using the range in this situation is only working for the first column of the range. So if my formula is:
=SUMIF('Data Referenced'!$A$2:$A,Formula!$A2,'Data Referenced'!$B$2:$M$11)
then it only adds as if I used the range B2:B. Using the same formula with internal ranges works fine as expected, so I'm not sure what I'm doing wrong.
I've laid out my example in the Google Doc linked below:
https://docs.google.com/spreadsheets/d/13zT2GlElgW5JkU90sOBeVlhr7FDOYeqaysDE-39fyao/edit?usp=sharing

use in B2:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, QUERY({'Data Referenced'!A2:A11,
MMULT('Data Referenced'!B2:M11*1,
SEQUENCE(COLUMNS('Data Referenced'!B2:M11))^0)},
"select Col1,sum(Col2) group by Col1"), 2, 0)))

Related

Is there a way to use arrayformula in google sheet to join text with conditions?

Is there a way to get the result column in the picture below?
All i want to do is text join the Col1 if the corresponding Col2 belongs to the same groups (E.G. 1,2,3....).
Reminded that I want to use arrayformula instead of dragging down the "normal" formula myself everytime.
Use this formula
Or Make a copy of this example sheet.
=ArrayFormula({"Result";
IF(A2:A="",,
BYROW(B2:B,
LAMBDA(v,JOIN(", ",FILTER(A2:A,B2:B=v)))))})
Great news for google-sheet lovers that google releases new lambda formulas. You can use BYROW() function to make it spill array. Try below formula.
=BYROW(C3:C9,LAMBDA(x,JOIN(",",FILTER(B3:B9,C3:C9=x))))
To refer entire column use FILTER() function for BYROW().
=BYROW(FILTER(C3:C,C3:C<>""),LAMBDA(x,JOIN(",",FILTER(B3:B,C3:C=x))))
Suppose my range of data from B3:C9, want to group the result according the the Column C (or Col2)
Here is the formula i googled without using the Lambda function
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(FLATTEN( QUERY(QUERY({ROW(C3:C9), C3:C9&"×", B3:B9&","}, "select max(Col3) where not Col2 starts with '×' group by Col1 pivot Col2"),,7^7)), "×")), ",$", ))
Notice the 7^7 is the (length of the data)^(length of the data).
i.e. from 3 to 9, there are 7 data.

SUMIF in Google Sheets for a month and if a column contains text

I have some simple data in the following format:
I need to make a sum of the last column, but based on the text in Domain column. The resulting table should be like this...given the text filtering needed, I'm not using pivot tables.
To do this, for July Domain 1 for example, I have a formula like this:
=SUMIFS(C:C, MONTH(A:A), 7, B:B, "domain1.")
And for the rest of the domains:
=SUMIFS(C:C, MONTH(A:A), 7, B:B, "<>domain1.")
I am using SUMIFS because I need the multiple conditionals. But this formula above gives an error:
Error: Array arguments to SUMIFS are of different size.
The columns are all structured as A:A, B:B, etc. What is going wrong?
Thanks.
MONTH(A:A)
will output only one cell unless you wrap your formula into INDEX or ARRAYFORMULA:
=INDEX(SUMIFS(C:C, MONTH(A:A), 7, B:B, "<>domain1.*"))
=ARRAYFORMULA(QUERY({TEXT(A2:A, "mmmm"), B2:C},
"select Col1,sum(Col3)
where not Col2 contains 'domain1.'
and Col3 is not null
group by Col1
label sum(Col3)''"))

Arrayformula not copying down when using AverageIF

Having trouble making ARRAYFORMULA copy down its values when using it in combination with AVERAGEIF. Here is my google sheet. It works fine when I copy down the formula, it just won't auto-populate.
Here is my current formula
=ARRAYFORMULA(AVERAGEIF(A2:A,A2,B2:B))
use:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, QUERY(A2:B,
"select A,avg(B)
where A is not null
group by A
label avg(B)''"), 2, 0)))

ArrayFormula, SumProduct and Google Sheets returning only 1 value

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.

Summing values based on multiple criteria. Columns are different sizes

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?

Resources