select sum(Col1),sum(Col2),sum(Col3) ... up to 500 columns but the number might increase or decrease... what is the best way to go about this with one formula?
it would be really nice if you could just do select sum(*) ... but sadly that does not seem to work.
you can do:
=ARRAYFORMULA(QUERY({A1:SF}, "select "&TEXTJOIN(",", 1, "sum(Col"&ROW(A1:A500)&")")))
or:
=ARRAYFORMULA(QUERY({A1:SF}, "select "&TEXTJOIN(",", 1, "sum(Col"&COLUMN(A1:SF)&")")))
or infinitely expanding:
=ARRAYFORMULA(QUERY({INDIRECT("A1:"&SUBSTITUTE(ADDRESS(1, COLUMNS(1:1), 4), 1, ))},
"select "&TEXTJOIN(",", 1, "sum(Col"&ROW(INDIRECT("A1:A"&COLUMNS(1:1)))&")")))
Related
Link to view-only sheet.Looking to find the cheapest flight plan between two points. There’s additional information on the sheet.
Available flights are of the form:
From
To
Price
Airport1
Airport2
100$
Airport2
Airport3
500$
Sample data with an intended output can be found on the sheet.
try:
=QUERY(SORTN(QUERY(SORT(A2:C6, 1, 1, 2, 1, 3, 1),
"where Col1<Col2", ), 9^9, 2, 1, 1),
"where Col1 >="&F1&" and Col2 <="&F2, )
In the below spreadsheet, I am trying to find the item with the highest total sales across various hours.
I would like to easily extract the highest and lowest selling item names as well as their corresponding total sales. I need to be able to do this without creating a helper column as I cannot edit the table.
I know there's probably an easy way to do this but for the life of me I cannot figure it out!
Link to Sheet
B12:
=INDEX(SORT(SPLIT(FLATTEN(B2:G10&"×"&A2:A10&"×"&B1:G1), "×"), 1, 0), 1, 2)
B13:
=INDEX(SORT(SPLIT(FLATTEN(B2:G10&"×"&A2:A10&"×"&B1:G1), "×"), 1, 0), 1, 1)
B14:
=INDEX(SORT(SPLIT(FLATTEN(B2:G10&"×"&A2:A10&"×"&B1:G1), "×"), 1, 1), 1, 2)
B15:
=INDEX(SORT(SPLIT(FLATTEN(B2:G10&"×"&A2:A10&"×"&B1:G1), "×"), 1, 1), 1, 1)
** edit: use player0's for the overall min and max.
Check this demo sheet
To get the highest or lowest by time slot (put this in I5),
=ARRAYFORMULA(
IFERROR(
VLOOKUP(
TRANSPOSE(B1:G1),
SORT(
SPLIT(
FLATTEN(B1:G1&"|"&A2:A&"|"&B2:G),
"|"),
3,FALSE),
{1,2,3},FALSE)))
Then to align the lowest per timeslot with that, put this in M5
=ARRAYFORMULA(
IF(ISBLANK(I5:I),,
IFERROR(
VLOOKUP(
I5:I,
SORT(
SPLIT(
FLATTEN(B1:G1&"|"&A2:A&"|"&B2:G),
"|"),
3,FALSE),
{2,3},FALSE))))
If you also wanted conditional formatting for the daily high and low, use a range of B2:G with
=AND(LEN(B2),MIN($B2:$G2)=B2)
If you really want to have these formulas below the table, change
FLATTEN(B1:G1&"|"&A2:A&"|"&B2:G),
to
FLATTEN(B1:G1&"|"&A2:A10&"|"&B2:G10),
I have a formula in a Google Sheet that is averaging the values in a row...
=AVERAGEIF(A2:L2,"<>0")
Simple, right?
However, I cannot figure out how to get the ARRAYFORMULA to work for this.
=ARRAYFORMULA(AVERAGEIF(A2:L,"<>0")
That formula only averages all of the cells in the range, instead of returning the average for each row. What am I missing?
you were close. try:
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A2:L),
"select "&TEXTJOIN(",", 1, IF(LEN(A2:A),
"avg(Col"&ROW(A2:A)-ROW(A2)+1&")", ))&"")),
"select Col2"))
then to add <>0 you need:
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(A2:L),
"select "&TEXTJOIN(",", 1, IF(LEN(A2:A),
"avg(Col"&ROW(A2:A)-ROW(A2)+1&")", ))&
"where "&TEXTJOIN(" and ", 1, IF(LEN(A2:A),
"not Col"&ROW(A2:A)-ROW(A2)+1&"=0", ))&"")),
"select Col2"))
Looking for a more efficient way, possibly array formula for Min/Max down a column. Not sure if array formulas work with this function as I can't get it to.
=ArrayFormula(MAX(INDIRECT("Data!E"&(K42:K169)&":E"&(K43:K170-1))))
=ARRAYFORMULA(MAX(VLOOKUP(K42:K169, {ROW(Data!A:A), Data!E:E}, 2, 0)&VLOOKUP(K43:K170-1, {ROW(Data!A:A), Data!E:E}, 2, 0)))
Note that I am using ROW(Data!A:A) instead of simply ROW(A:A) because the range in current sheet doesn't fit that of sheet Data!.
Here is my current code copied down columns in my sheet.
=MAX(INDIRECT("Data!E"&(K42-1)&":E"&(K43-1)))
Just need a more efficient way. Am I correct that using INDIRECT results in slow calculation times.
=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(
INDIRECT("Data!E"&K42&":E"&MAX(K42:K))&","&IF(MOD(ROW(
INDIRECT("Data!A1:A"&COUNTA(L42:L)*K41)), K41)=0, "♦", ),,999^99), "♦")), ","),
"where Col2 is not null", 0)),
"select "&TEXTJOIN(",", 1, IF(LEN(L42:L),
"max(Col"&ROW(A42:A)-ROW(A42)+1&")", ))&"")),
"select Col2"))
I am setting up a shift roster. The top row is sequential dates, and the leftmost rows are staff names. A staff member can look along their row to see which shifts they are on for the coming weeks.
I want to automatically pull out the allocated shifts into another sheet to show a dynamic "Today's Staffing" which shows who is on duty in each role for the day e.g. for column TODAY'S DATE find which row contains MORNING SHIFT and return the FIRST COLUMN FOR THAT ROW which should contain the name.
I have access to both MS Excel and Google Sheets.
Is there a function/way that I can do this?
Example google sheet:
https://docs.google.com/spreadsheets/d/1VTYK39xuHT0-4s8O5398dnseXYsE0q54-os-rJNNVB8/edit?usp=sharing
=QUERY({INDIRECT(ADDRESS(2, MATCH(TODAY(), A1:1, 0), 4)&":"&
SUBSTITUTE(ADDRESS(1, MATCH(TODAY(), A1:1, 0), 4), 1, )), A2:A},
"where Col1 <>'OFF' and Col1 <>''")
if you want to run this under with just 3 people do:
=QUERY({INDIRECT(ADDRESS(2, MATCH(TODAY(), Sheet1!A1:1, 0), 4)&":"&
SUBSTITUTE(ADDRESS(4, MATCH(TODAY(), Sheet1!A1:1, 0), 4), 1, )), Sheet1!A2:A4},
"where Col1 <>'OFF' and Col1 <>'' order by Col1 desc")