I have a Google Sheet which figures are manually entered in to in order to record activity across a variety of sites. The sheet contains a date column with each date as a row value. It then has three columns (Total tests, Total positives, Total voids) which are repeated for each site. There are 10 sites (which will grow) so for not there are 10 total tests, 10 total positives, 10 total void columns.
What I would like to do is sum a total based on the column name so that each day, it is automatically adding the total tests across all the sites, the total positives and total voids.
I tried using a SUM calculated field on a pivot table but when I did this, using 'Total tests', it only picked up the first column with this name and did not sum all of the columns with that name.
Is there a way using a pivot table (or alternative means) to sum the daily totals for those columns with the same name?
your sheet has a predictive layout (eg. each site has always 3 columns) so you can sue MOD of 3 to always get every 3rd column and sum them:
AH3:
=INDEX(MMULT(1*FILTER(C3:AF, MOD(COLUMN(C:AF), 3)=0), SEQUENCE(COLUMNS(
FILTER(C3:AF, MOD(COLUMN(C:AF), 3)=0)), 1, 1, 0)))
AI3:
=INDEX(MMULT(1*FILTER(C3:AF, MOD(COLUMN(C:AF)-1, 3)=0), SEQUENCE(COLUMNS(
FILTER(C3:AF, MOD(COLUMN(C:AF)-1, 3)=0)), 1, 1, 0)))
AJ3:
=INDEX(MMULT(1*FILTER(C3:AF, MOD(COLUMN(C:AF)-2, 3)=0), SEQUENCE(COLUMNS(
FILTER(C3:AF, MOD(COLUMN(C:AF)-2, 3)=0)), 1, 1, 0)))
to remove zeros you can do this in AH3:
=INDEX(IFERROR(1/(1/MMULT(1*FILTER(C3:AF, MOD(COLUMN(C:AF), 3)=0), SEQUENCE(COLUMNS(
FILTER(C3:AF, MOD(COLUMN(C:AF), 3)=0)), 1, 1, 0)))))
update:
=ARRAYFORMULA(QUERY(QUERY({IF(A3:A<>"",ISOWEEKNUM(A3:A),),
MMULT(1*FILTER(C3:AF, MOD(COLUMN(C:AF), 3)=0), SEQUENCE(COLUMNS(
FILTER(C3:AF, MOD(COLUMN(C:AF), 3)=0)), 1, 1, 0)),
MMULT(1*FILTER(C3:AF, MOD(COLUMN(C:AF)-1, 3)=0), SEQUENCE(COLUMNS(
FILTER(C3:AF, MOD(COLUMN(C:AF)-1, 3)=0)), 1, 1, 0)),
MMULT(1*FILTER(C3:AF, MOD(COLUMN(C:AF)-2, 3)=0), SEQUENCE(COLUMNS(
FILTER(C3:AF, MOD(COLUMN(C:AF)-2, 3)=0)), 1, 1, 0))},
"select Col1,sum(Col2),sum(Col3),sum(Col4) where Col2 > 0 group by Col1"),
"offset 1", 0))
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"))
I have a formula that allows me to join multiple rows together and remove duplicates:
=TEXTJOIN(" ", 1, UNIQUE(TRANSPOSE(FILTER(Sheet1!A:D, NOT(REGEXMATCH(LOWER(Sheet1!A:D), "n/a"))))))
The issue I'm running in to is because this references another tab in the same sheet, it cannot be sorted by different columns without changing the results.
So what I'd like to know is: how do I modify the above formula so that it pulls the data it needs based on criteria I give it? Note this will need to be across a range of cells and includes strings of text.
After your comment I understand what you are trying to do. Basically you want to retrieve an information of the first sheet matching with your "row key".
Is there any reason why you haven't used a VLOOKUP?
For example using this formula:
=IFNA(VLOOKUP(A1,Sheet1!A:G, 7, FALSE), "VALUE NOT FOUND")
If you sort or randomize the range of column B you get a result like this:
In here you see that every description keeps up with its key.
EDIT: So after your comment it seems that you don't have your information inside a single cell. You could create this cell as a placeholder to later retrieve the information.
Or if you need you could make this inside the formula, that could make this a little messy but still could be workable.
=TEXTJOIN(" ", 1,
UNIQUE(
TRANSPOSE(
FILTER({VLOOKUP(A1, Sheet1!A:G, 3, FALSE), VLOOKUP(A1, Sheet1!A:G, 4, FALSE), VLOOKUP(A1, Sheet1!A:G, 5, FALSE), VLOOKUP(A1, Sheet1!A:G, 6, FALSE)},
NOT(LOWER({VLOOKUP(A1, Sheet1!A:G, 3, FALSE), VLOOKUP(A1, Sheet1!A:G, 4, FALSE), VLOOKUP(A1, Sheet1!A:G, 5, FALSE), VLOOKUP(A1, Sheet1!A:G, 6, FALSE)}) = "n/a")
)
)
)
)
try:
=ARRAYFORMULA(IFNA(VLOOKUP(TO_TEXT(B1:B), {QUERY(TRANSPOSE(QUERY(QUERY(
UNIQUE(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(Sheet1!C:E="",,"♥"&ROW(Sheet1!C:C)&"♦"&Sheet1!C:E)),,999^99)),,999^99), "♥")), "♦"))),
"where not lower(Col2) matches 'n/a'", 0),
"select max(Col2) group by Col2 pivot Col1")), "select Col1", 0), TRANSPOSE(QUERY(QUERY(
QUERY(QUERY(UNIQUE(TRIM(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(Sheet1!C:E="",,"♥"&ROW(Sheet1!C:C)&"♦"&Sheet1!C:E)),,999^99)),,999^99), "♥")), "♦"))),
"where not lower(Col2) matches 'n/a'", 0),
"select max(Col2) group by Col2 pivot Col1"), "offset 1", 0),,999^99))}, 2, 0)))
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)))&")")))