How to sum multiple columns using a single formula in Google Sheets? - google-sheets

The data that i have is in a 2D fashion
I want the output in this type of schema using a Single Formula!
I've tried PIVOT and SUMIF,SUMIFS,QUERY functions. But, Alas unable to figure out the same. Can anyone please help me with this

You can use SUMPRODUCT for this task.
Formula B12 dragged right and down:
=SUMPRODUCT($B$5:$I$8*($A$5:$A$8=$A12)*($B$3:$I$3=B$11))
Result:
Pay attention at all those $ when adapting to your ranges.

you can also try this single formula to create the summary table.
=LAMBDA(x,y,{{"",y};x,MAKEARRAY(COUNTA(x),COUNTA(y),LAMBDA(r,c,SUM(FILTER(FILTER(B3:I,B1:I1=INDEX(y,,c)),A3:A=INDEX(x,r)))))})(FILTER(A3:A,A3:A<>""),UNIQUE(FILTER(B1:I1,B1:I1<>""),1))

Related

how can I write a formula that uses a cell's contents when building a range reference to the name of another sheet?

I have a large Google Sheets spreadsheet that has individual sheets for financial statements of activity for multiple years. I want to reference particular columns of those in other sheets, and I've successfully figured out how to do that with an HLOOKUP function. However, because I want to do this for multiple years, I'd like that HLOOKUP function to pick up the name of the sheet to reference from its column header. Right now, I'm hard-coding it like this—you can see the HLOOKUP range refers to cells in the "2021 Overall" sheet. The hard-coded approach works but makes adding a new year tedious. Ideally, the HLOOKUP formula would read the contents of its column header cell to determine which year it is.
As best I can tell, the solution is to use INDIRECT, but I can't figure out any way to build the formulate with INDIRECT and not get an error. For instance, this seemed like it should work. As you can see, I have 2021 in cell D4, and my INDIRECT statement is referencing that and building the rest of the range.
I've also tried using INDIRECT with an explicit CONCATENATE, with no more success.
Any ideas for how to look up that D4 cell and slide it into the HLOOKUP range?
Thank you!
Try to remove the "'"& before D4 and the ' after the Overall.
Your formula should look like this:
=IFERROR(HLOOKUP($A$2,INDIRECT(F4 &" Overall!$A$5:$X$150", Utility!$A10, FALSE)))
With Nikko's nudges in the right direction, I eventually figured out the right format. This allows the formula to work in multiple sheets and to be filled right (for more years) and down (for more classes).
=IFERROR(HLOOKUP($A$2,INDIRECT("'"D$4&" Overall'!$A$5:$X$150"), Utility!$A3, FALSE))
Note that if you try to replicate this, you may need to type the formula out from scratch—I had a problem where pasting it in didn't work. Once I'd retyped it and Google Sheets acknowledged it, it worked from then on in the spreadsheet, even when pasted from sheet to sheet.

Google Sheets: Is it possible to simplify this formula? Preferably, I'd like it to calculate all the cells in the row

Can the following formula be simplified as described in the paragraph below it?
=(ABS(D$3-D5)+ABS(E$3-E5)+ABS(F$3-F5)+ABS(G$3-G5)+ABS(H$3-H5)+ABS(I$3-I5)+ABS(J$3-J5)+ABS(K$3-K5))/-1
The problem is that I don't know how many columns I'm going to end up with, and I certainly don't want to continue manually writing each column into the formula. Is there I way to simplify this formula so that every column in a row is calculated?
I've been trying various formulas to no avail, and I can't get usable results via Google searches. I suppose I don't know how to effectively word the question without writing a paragraph.
Thanks, in advance!
Try this one:
=-SUM(ARRAYFORMULA(ABS(D$3:$3 - D5:5)))
GOT IT:
=ArrayFormula(SUM(ABS(D$3:$3-D5:5))/-1)

Google Sheets: Use ArrayFormula for JoinText for multiple columns

I want to Use ArrayFormula for JoinText for multiple columns which have their own ArrayFormulas in Google Sheets.
My formula works for columns that have plain text values but for some reason Google Sheets gives me an error when I apply it to columns that have their own ArrayFormulas applied to them.
Take a look at the example sheet I've created HERE
Any help will be appreciated!
I hope this solution with query is helpful for you:
=ArrayFormula(transpose(query(transpose(C1:D),,2)))
(Will work faster if you know the limit of the range, e.g. C1:D10).
For implementing commas between the columns you can use
=ARRAYFORMULA(IF(C1:C="",D1:D,if(D1:D="",C1:C,C1:C&", "&INDIRECT("D1:D"))))
I put this formula in cell I2 on your sample sheet. It should be relatively fast for many thousands of rows.
=ARRAYFORMULA(SUBSTITUTE(TRIM(C2:C&CHAR(10)&D2:D),CHAR(10),", "))

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.

Running total with two criteria - seeking arrayformula or app script

I have a google sheet with a list of [people], [dates], and [times]. I need a running total column that gives me a running time total on each line for each combination of name and date, as of that line. I have a working SUMIFS solution. The drawback of this solution is that it requires me to copy the formula down the entire column. Since I ultimately want this to work in a sheet that is fed by a form, I want to use either an ARRAYFORMULA or an APP SCRIPT solution, so that each new row will automatically do the calculation without my needing to copy down the formula.
You can see what I mean in this sample sheet:
https://docs.google.com/spreadsheets/d/1G6cgwwcL6LfnbVUhn8PrMYxrUSImkmgOGvPspparhSI/edit?usp=sharing
Thanks for any thoughts you may have.
-DH
SUMIF() does not play nice with ARRAYFORMULA(). Have a look at this MMULT example spreadsheet, last sheet "Cumulative sum down column", column U
https://docs.google.com/spreadsheets/d/1NJPAt5iFQWIyxHx35bpCh6zjVeKon4rdTPk-dfyZDrU/edit#gid=420781522
If you haven't used matrix multiplication before, and have trouble wrapping your head around the solution, try to follow the examples starting from the 1st sheet.

Resources