Combining ARRAYFORMULA and SUMIF to summarize Google Form responses - google-sheets

I have a Google Form linked to a Google Sheet. The form consists of twenty questions, all of which are answered by a 0, 1, 2, 3, 4, or 5 response. In the sheet, there are 20 columns that correspond to the questions. Each row is the response of one subject.
Now the tricky part: there are six additional columns that sum all the 0's, 1's, 2's, 3's, 4's, 5's. For example, if a subject answers three of the questions with a value of 3, the value of 9 will populate the "3" column. I have been successful using the SUMIF formula, but copying and dragging down the column doesn't work because of the Google Form integration.
I understand the premise of array formulas, and I have discovered that it doesn't work with SUMIF.
I have spent the better part of two days searching for solutions including combining SUM and FILTER, HLOOKUP, and MMULT. I just can't solve this.
Any help is much appreciated.
Rich

Aggregating functions such as sum() will not produce multi-cell results in an arrayformula() wrapper.
Some other aggregating functions that are not conducive for use in an array formula are listed below with examples of workarounds for producing row-by-row results.
and, avarage, count, countif, counta, concatenate & join, max & min
The sample file with more examples:
Make a copy
Sumif
={"Mmult" ; MMULT(FILTER(B2:H * (B2:H = 3), A2:A<>"") , ARRAYFORMULA(TRANSPOSE(COLUMN(B1:H1)^0))) }
Mmult function works slow, but I can't find a better solution.

Related

ARRAYFORMULA should be used only once in each formula or should it be used multiple times once for each need?

Sum the VLOOKUP results:
=ARRAYFORMULA(SUM(IFERROR(VLOOKUP(A1:A,B1:C,2,FALSE))))
Sum two cells:
=(Z1+Z2)
Sum two specific values from VLOOKUP:
=ARRAYFORMULA(SUM(IFERROR(VLOOKUP(G1:G2,H1:I,2,FALSE))))
Now I need to come up with an average of the three results:
=ARRAYFORMULA(
SUM(IFERROR(VLOOKUP(A1:A,B1:C,2,FALSE)))+
(Z1+Z2)+
SUM(IFERROR(VLOOKUP(G1:G2,H1:I,2,FALSE)))
)/3
But the faithful form would be:
=(
ARRAYFORMULA(SUM(IFERROR(VLOOKUP(A1:A,B1:C,2,FALSE))))+
(Z1+Z2)+
ARRAYFORMULA(SUM(IFERROR(VLOOKUP(G1:G2,H1:I,2,FALSE))))
)/3
Both will reach the same result, my question is, what is the most correct and safe way from the standards of those who work professionally with Google Sheet?
1 → Use only one ARRAYFORMULA call for the all the formula.
2 → Use multiple ARRAYFORMULA calls, one for each specific need.
Question reason:
I still haven't found risks of using a single ARRAYFORMULA in the beginning and doing everything else within it like =ARRAYFORMULA((...)+(...)) rather than =ARRAYFORMULA(...)+ARRAYFORMULA(...), but I not finding risks doesn't mean they don't exist.
One instance of ArrayFormula on the outside is both sufficient and the professional standard.
However, I must say that I don't understand your formula usage or intention from your posted example. You've got + between each element, which is redundant to SUM. And like ArrayFormula, you only need one outer SUM to sum all elements in your usage.

VLOOKUP in multiple ranges Google Sheets

I have a VLOOKUP formula to lookup from a different sheet as below:
=ARRAYFORMULA(IFERROR(VLOOKUP(B2:B6,Sheet3!A2:C,2,0)))
I would now like to expand the data on Sheet 3 but would like the next batch of data to be in range E2:G. Is it possible to have a VLOOKUP across 2 different ranges like this?
I've done lots of google searching without any joy tonight so thought I'd ask the question on here to make sure I'm not trying the impossible.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(B2:B6, {Sheet3!A2:C; Sheet3!E2:G}, 2, 0)))

google sheets array formula sumifs repeats first value for all values in array

I'm trying to do a form autocomplete formula like "Ben Collin's Tutorial" that adds more formulas down a column as values are added in an adjacent column. This works with if functions, sum, basic arithmetic etc. but with sumifs, the first value is repeated. There have been attempted solutions on stackoverflow before, but it relies on the keys to be as long as the display or it uses queries so that the columns have to be adjacent or well behaved. Really, the vocabulary and labels are sufficient or consistent enough to describe the problem with an example so I made one on google sheets.
The formula in e2 is:
=arrayformula(if($A2:$A<>"",sumifs(data!C:C,data!A:A,$A2:$A,data!B:B,"k"),""))
It would be nice if the results were the results of column f. I don't know what is going on in the background so that this would ever be a desired results, but I also tried this, and it failed.
=arrayformula(if(A2:A<>"",sumifs(data!C:C,data!A:A,A2:A,data!B:B,"k"),""))
or
=arrayformula(if(A$2:A<>"",sumifs(data!C:C,data!A:A,A$2:A,data!B:B,"k"),""))
Suffice it to say, the $ don't work here the way they work with conditional formatting rules, which is a pity.
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, QUERY(data!A2:C,
"select A,sum(C) where B = 'k' group by A"), 2, 0)))

Google Sheets, Is it possible to use Arrayformula to expand formulas downward when the formula uses arrays

I've been using Arrayformula to auto-expand formulas (such as "=Left(A2:A,B2:B-1") downward, but I need some help understanding this formula. I've read up on the function itself and browsed many forums about this but I can only find articles explaining how to use this with simple formulas, so I'm going to try to as this as simply as possible here: Is it possible to use Arrayformula to expand formulas downward when the formula uses arrays?
The summary for Arrayformula reads "Enables the display of values returned from an array formula into multiple rows and/or columns and the use of non-array functions with arrays." This was my understanding of how Arrayformula populated a formula into rows automatically. Using this I thought of it as writing a formula that generated an array of formulas, and then splitting them up with Arrayformula. This seems to not work with some formulas such as concatenate, which I will focus my question on. This example is far from my real life problem, but if someone could show me a solution I can apply it elsewhere.
Arrayformula spreadsheet example
Usually when I use Arrayformula with A1:A it would expand the formula through the column, referencing the corresponding rows as it went. With this example I want to have Column C be the concatenated result of columns A and B. Is this possible with Arrayformula? This question is not specific to concatenate, that is just the simplest one that came to mind. Another example would be Countif. Lets say I want to see how many values in the first 5 columns are over 20, and I want that formula to auto populate down, is that possible and if so how would it be done?
Arrayformula second example
P.S. Please don't say copy the formula using the drag handle in the lower right.

Using VLOOKUP in an array formula on Google Spreadsheets

Effectively I want to give numeric scores to alphabetic grades and sum them. In Excel, putting the LOOKUP function into an array formula works:
{=SUM(LOOKUP(grades, scoringarray))}
With the VLOOKUP function this does not work (only gets the score for the first grade). Google Spreadsheets does not appear to have the LOOKUP function and VLOOKUP fails in the same way using:
=SUM(ARRAYFORMULA(VLOOKUP(grades, scoresarray, 2, 0)))
or
=ARRAYFORMULA(SUM(VLOOKUP(grades, scoresarray, 2, 0)))
Is it possible to do this (but I have the syntax wrong)? Can you suggest a method that allows having the calculation in one simple cell like this rather than hiding the lookups somewhere else and summing them afterwards?
I'm afraid I think the answer is no. From the help text on
http://docs.google.com/support/spreadsheets/bin/answer.py?answer=71291&query=arrayformula&topic=&type=
The real power of ARRAYFORMULA comes when you take the result from one of those computations and wrap it inside a formula that does take array or range arguments: SUM, MAX, MIN, CONCATENATE,
As vlookup takes a single cell to lookup (in the first argument) I don't think you can get it to work, without using a separate range of lookups.
Google Spreadsheets does not appear to have the LOOKUP function
Presumably not then but it does have now:
grades Sheet1!A2:A4
scoringarray Sheet1!A2:B4
I still can't see the formulae in your example (just values), but that is exactly what I'm trying to do in terms of the result; obviously I can already do it "by the side" and sum separately - the key for me is doing it in one cell.
I have looked at it again this morning - using the MATCH function for the lookup works in an array formula. But then the INDEX function does not. I have also tried using it with OFFSET and INDIRECT without success. Finally, the CHOOSE function does not seem to accept a cell range as its list to choose from - the range degrades to a single value (the first cell in the range). It should also be noted that the CHOOSE function only accepts 30 values to choose from (according to the documentation). All very annoying. However, I do now have a working solution in one cell: using the CHOOSE function and explicitly listing the result cells one by one in the arguments like this:
=ARRAYFORMULA(SUM(CHOOSE(MATCH(D1:D8,Lookups!$A$1:$A$3,0),
Lookups!$B$1,Lookups!$B$2,Lookups!$B$3)))
Obviously this doesn't extend very well but hopefully the lookup tables are by nature quite fixed. For larger lookup tables it's a pain to type all the cells individually and some people may exceed the limit of 30 cells.
I would certainly welcome a more elegant solution!
I know this thread is quite old, but I'd been struggling with this same problem for some time. I finally came across a solution (well, Frankenstiened one together). It's only slightly more elegant, but should be able to work with large data sets without trouble.
The solution uses the following:
=ARRAYFORMULA(SUM(INDIRECT(ADDRESS(MATCH(), MATCH())))
as a surrogate for the vlookup function.
I hope this helps someone!
you can do so easily like this by hardcoding it in VR table:
=SUM(IFERROR(ARRAYFORMULA(VLOOKUP(A2:A, {{"A", 6};
{"B", 5};
{"C", 4};
{"D", 3};
{"E", 2};
{"F", 1}}, 2, 0)), ))
or you can use some side cells with rules:
=SUM(IFERROR(ARRAYFORMULA(VLOOKUP(A2:A, E2:F, 2, 0)), ))
alternatives: https://webapps.stackexchange.com/a/123741/186471

Resources