Link to example Google spreadsheet that can be edited anonymously.
Query Formula
- Place this formula in C1 of a different sheet than Data.
- Teams to exclude in A2:A
- Headings to include B2:B
=INDEX(LET(
data,Data!A1:F, valT,TOCOL(A2:A,1), vaL,TOCOL(B2:B,1),
off,OFFSET(data,,1,,COLUMNS(data)-1), colO,COLUMN(off),
reL,REGEXMATCH(INDEX(off,1), "(?i)"&JOIN("|", vaL)),
colN,IF(COUNTA(vaL), FILTER(colO, reL), INDEX(colO)),
sumQ," SUM(Col" & JOIN(")," & " SUM(Col", colN) & ")",
colQ,IF(COUNTA(valT), "AND ("& JOIN(" AND ",
INDEX("Col1 <> '" & valT &"'"))&") ",),
IFNA(QUERY(data, "Select Col1,"& sumQ &
" Where Col1 <> '' "& colQ & " Group by Col1"))))
Link to sheet Query of document 'WebApps Question 176666'
Query_Extended Formula
- Adds the ability to toggle between including/excluding Team and Heading search strings
=INDEX(LET(
data,Data!A1:F, onT,A2, onL,D2, inT,A3, inL,D3,
valT,TOCOL(B4:B,1), vaL,TOCOL(E4:E,1), sumC," SUM(Col",
delT,IF(inT," OR ", " AND "), eqT,IF(inT, " = '", " <> '"),
off,OFFSET(data,,1,,COLUMNS(data)-1), colO,COLUMN(off),
reL,REGEXMATCH(INDEX(off,1), "(?i)"&JOIN("|", vaL)),
colN,IF(onL*COUNTA(vaL),
FILTER(colO, IF(inL, reL, NOT(reL))), INDEX(colO)),
sumQ,sumC & JOIN(")," & sumC, colN) & ")",
colQ,IF(onT*COUNTA(valT), "AND ("& JOIN(delT,
INDEX("Col1"& eqT & valT &"'"))&") ",),
IFNA(QUERY(data, "Select Col1,"& sumQ &
" Where Col1 <> '' "& colQ & " Group by Col1"),
{"All results excluded by column label filter!";""})))
Link to sheet 'Query_Extended' of document 'WebApps Question 176666'