1
votes

In Google Sheets, I have a spreadsheet that looks like this

A1    A2    A3    B1    B2    B3    C1    C2    C3
55    23    21    15    18    15    61    51    51
51    15    15    81    98    13    51    74    65
15    87    89    99    32    72    15    58    51
18    64    15    81    32    15    81    78    98
87    81    32    51    15    35    15    81    12

I want to create a separate sheet that will find the sum/max/average/min of all the "A" named columns.

Is there a way to make a function in a cell that will (lets' pick one for now) average all the cells in the same row whose column names match a certain text pattern (e.g. "A*")?

2

2 Answers

0
votes

You can use an array formula like this:

ArrayFormula(average(if(left(A1:I1,1)="A",A2:I)))

enter image description here

Or if preferred use pattern matching for more flexibility:

=ArrayFormula(average(if(regexmatch(A1:I1,"^A"),A2:I)))

(case sensitive).

0
votes
=ARRAYFORMULA({
 "sum",         SUM(QUERY(TRANSPOSE(QUERY(TRANSPOSE(TO_TEXT(A1:I)), 
 "where Col1 contains 'A'", 0)), "where Col1 !='' offset 1", 0)*1);
 "max",         MAX(QUERY(TRANSPOSE(QUERY(TRANSPOSE(TO_TEXT(A1:I)), 
 "where Col1 contains 'A'", 0)), "where Col1 !='' offset 1", 0)*1);
 "average", AVERAGE(QUERY(TRANSPOSE(QUERY(TRANSPOSE(TO_TEXT(A1:I)), 
 "where Col1 contains 'A'", 0)), "where Col1 !='' offset 1", 0)*1);
 "min",         MIN(QUERY(TRANSPOSE(QUERY(TRANSPOSE(TO_TEXT(A1:I)), 
 "where Col1 contains 'A'", 0)), "where Col1 !='' offset 1", 0)*1)})

0


=ARRAYFORMULA(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
 QUERY(TRANSPOSE(QUERY(TRANSPOSE(TO_TEXT(Raw!$A1:$AR)), 
 "where Col1 contains '"&REGEXEXTRACT(C1, ".")&"'", 0)), 
 "where Col1 !='' offset 1", 0)*1), 
 "select "&REGEXREPLACE(JOIN( , IF(LEN(Raw!$C2:$C),
 "max(Col"&ROW(Raw!$C2:$C)-ROW(Raw!$C2)+1&"),", )), ".\z", "")&"")),
 "select Col2"))

0