How to refer table column by column heading/name in google sheet - google-sheets

(I might have used wrong terminology to frame question, and it would be great to be pointed at right question/answer.)
As shown in image I have a table.
I want to sum all the values in "col2"
One way to do this is
=sum(B2:B4)
But I think a cleaner way to do this would involve somehow referring the column name in the formula, so that formula is more readable.
Is there a way to do it?

You could try this too
=sum(filter(A2:C4,A1:C1="col2"))

Try
=SUM(offset(A2:A,,MATCH("Col2",1:1,0)-1))

Try this formula:
=SUM(INDIRECT("C"&MATCH("col2", 1:1, 0),FALSE))
Output:
References:
INDIRECT
MATCH
SUM

Related

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)

Spreadsheet - I want to append data from one sheet to another, they only have one column that can be used as a reference

I have two sheets that only have one column in common - ID column.
I'd like to compare those two columns and if id's match, to append data into Sheet 1 from the matching row.
I don't know if I'm clear enough so here is what I'm trying to achieve:
I've tried looking for any solution, but it's a bit too specific.
Hopefully someone here can explain how can I achieve this?
If you want an one formula solution then use this in cell D2 of Sheet1:
=arrayformula({iferror(vlookup(A2:A, {Sheet2!A2:A,Sheet2!B2:B},2,false),""),iferror(vlookup(A2:A, {Sheet2!A2:A,Sheet2!C2:C},2,false),""),
iferror(vlookup(A2:A, {Sheet2!A2:A,Sheet2!D2:D},2,false),""),iferror(vlookup(A2:A, {Sheet2!A2:A,Sheet2!E2:E},2,false),"")
})
A better alternative suggested by marikamitsos is this:
=ArrayFormula(IFERROR(VLOOKUP(A2:A,Sheet2!A2:E,{2,3,4,5})))
Try below.
=INDEX(Sheet2!B:B,MATCH(A2,Sheet2!A:A,0))
If you want Vlookup() then use-
=VLOOKUP($A2,Sheet2!$A:$E,COLUMN(B$1))

Google Sheets FORMULATEXT not updating

So FORMULATEXT is not updating when the referenced objects are changed even tho the formula that it's turning to text has changed.
https://docs.google.com/spreadsheets/d/1V00i3XlEx5Q2Xp0QZevS5o2pdpU2QNNNX5d8bkHtn3U/edit?usp=sharing
Any other ways to achieve this or a way to fix this?
I don't know whether it's the smartest solution, but this will work, assuming your reference object columns moves between Column E to N, you can edit the formula per your requirement
=(regexextract(ADDRESS(row(),column(index(E1:N1,match(sum(E1:N1),E1:N1,0)))),"[A-z]"))&":"&(regexextract(ADDRESS(row(),column(index(E1:N1,match(sum(E1:N1),E1:N1,0)))),"[A-z]"))>0
Hope it helps!
set calculation to:
and try:
=FORMULATEXT(A1)&IFERROR(NOW()/0)

ARRAYFORMULA COUNTIF each row separately

I try to COUNTIF(B2:Q2;">5") for each row and return the result for each row in column A but I clearly fail on using ARRAYFORMULA for this purpose.
Could you help?
In addition to Max's solution, I believe it should be possible to use COUNTIF(). See if this works
=ARRAYFORMULA(COUNTIF(IF(B2:Q>5,ROW(B2:B)), ROW(B2:B)))
Sample File
=ARRAYFORMULA(MMULT(FILTER(--(B2:Q>5),B2:B<>""),TRANSPOSE(COLUMN(B2:Q)^0)))
mmult is effective, but slow formula. I used filter to limit the number of calculations.
Edit. Here's another formula to do the same:
=ArrayFormula(LEN(SUBSTITUTE(SUBSTITUTE(TRANSPOSE(QUERY(TRANSPOSE(FILTER(--(B2:Q>5),B2:B<>"")),,100500)),"0", "")," ","")))
Looks clunky but should work faster (not tested).

Reorder/reverse column order

I want to change the columns order in google sheet from this:
To this
I know I can do this manually but if I have a lot of columns it's pretty annoying.
There's a simple way to do this?
Thanks in advance!
Building on the idea proposed by Steve in the comment. This works for any arbitrary range, pasted as tested on a range of columns A to D:
=array_constrain(
transpose(sort(transpose({A:D; arrayformula(column(A:D))}), rows(A:D)+1, false)),
rows(A:D),
columns(A:D)
)
Explanation: the 1st argument does the inversion magic by inserting a row of column numbers, transposing, sorting by this row in descending order and transposing back. Then we get rid of this extra row by constraining the result to the original dimensions.
The formula works and is generic enough, but it still feels like a hack. I wonder if someone can come up with a cleaner solution.

Resources