Can you help me with below using Google Sheets to transform the Google Form data below to have a list of activities with a list of potential attendees?
Context:
How do I switch the table to sort the data by indvidual activity, so I have the following format sorted by activity:
The expected results are constructed in several stages:
Final Outcome
1. Split and transpose results over 2 columns
=query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")
Refer: How to transpose & split multiple columns and repeat specific cells in a column
2. Group everything by Email; Activities as a comma-delimited list
=query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col1")
Refer: Group everything by Column A and have Column B be a comma-delimited list of values
3. Count number of email addresses for each Activity
={"Number of Attendees";arrayformula(if(N2:N<>"",iferror(len(regexreplace(N2:N,"[^@^]","")),),))}
Refer: Count occurrences of string in a single cell in Google Sheets
4. Create "helper" queries as substitutes in Filter formula
=query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col1")
``
=query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col2")
5. Combine everything into a single formula
={UNIQUE(FILTER(query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col2"), query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col1")<>"")),{"Number of Attendees";arrayformula(len(regexreplace(BYROW(UNIQUE(FILTER(query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2")},"select Col2"), query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2")},"select Col1")<>"")), LAMBDA(aa, JOIN(", ", FILTER(query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2")},"select Col1"), query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2")},"select Col2")=aa)))),"[^@^]","")))}, BYROW(UNIQUE(FILTER(query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col2"), query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col1")<>"")), LAMBDA(aa, JOIN(", ", FILTER(query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col1"), query({query({ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT(B2:B5, ", ",false))="",, if(A2:A5="","none",A2:A5)&"×"&SPLIT(B2:B5, ", ",false))), "×"), "where Col2 is not null")))},"select Col1, Col2 label Col1 'Email', Col2 'Activity'")},"select Col2")=aa))))}
Raw Data
Stage 1 - split and transpose results over 2 columns
Stage 2 - group by Activity; comma-delimited email addresses
Stage 3 - Count email addresses in each Activities row
Stage 4 - Helper queries