Displayt comma seperated list of values in pivot table - google-sheets

I have a spreadsheet with one column of keywords and a second column list of URLs/landing pages. The keywords are unique but the URLs are limited e.g.
Column 1:
keyword1
keyword2
keyword3
keyword7
keywordabc
keyworddef
keywordxyz
Column 2:
example.com/landingpage1
example.com/landingpage2
example.com/landingpage4
example.com/landingpage1
example.com/landingpage3
example.com/landingpage1
example.com/landingpage2
What I'm trying to achieve is a pivot table output that shows the landing page and its matching keywords so e.g.
example.com/landingpage1 | keyword1, keyword7, keywordabc, keywordxyz
example.com/landingpage2 | keyword2, keyword3, keyworddef
Any help would be appreciated.

use:
=INDEX(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(QUERY(
{A1:A&",", B1:B&"×"},
"select max(Col1)
where not Col1 starts with ','
group by Col1
pivot Col2"),,9^9)), "×")), ",$", ))

Related

Google Sheets Query Filter by Multiple Variables

Is there a better way of writing this formula out? I mean it works but there has to be a better way of doing it where I can have multiple Search parameters.
I am using a search box to then that splits the cell with this formula =if(E1="","", if(REGEXMATCH(E1,";"),SPLIT(E1,";"),E1))
https://docs.google.com/spreadsheets/d/1-ymDylwRjd0zYnu3m0uxCz8hAavnL5Sxx39YrtlWylc/edit?usp=sharing Example Sheet
=if(E1="",QUERY(IMPORTRANGE("Spreadsheetidabcd", "RawData!A:Z"), "Select Col1,Col12,Col2,Col10,Col3 where (Col11='')",1),QUERY(IMPORTRANGE("Spreadsheetidabcd", "RawData!A:Z"), "Select Col1,Col12,Col2,Col10,Col3 where Col1 contains '"&$F$1&"' or Lower(Col12) contains Lower('"&$F$1&"') or Lower(Col12) contains Lower('"&$G$1&"')or Lower(Col10) contains Lower('"&$F$1&"')or Lower(Col10) contains Lower('"&$G$1&"')or Lower(Col2) contains Lower('"&$F$1&"')or Lower(Col2) contains Lower('"&$G$1&"')or Col3 contains '"&$F$1&"' or Col3 contains '"&$G$1&"'or Col4 contains '"&$F$1&"'or Lower(Col5) contains Lower('"&$F$1&"')"))
You can try this one, although this returns the row if any of the columns contain the values of either F1 or G1 (I assume that's what your search box is for, to find the rows containing the search term).
Formula:
=if(E1="",
QUERY(IMPORTRANGE("Spreadsheetidabcd", "RawData!A:Z"), "Select Col1,Col12,Col2,Col10,Col3 where (Col11='')",1),
arrayformula(split(query({transpose(split(textjoin(",", true, QUERY(IMPORTRANGE("Spreadsheetidabcd", "RawData!A:Z"), "Select Col1, Col12, Col2, Col10, Col3, ';' label ';' ';'")), ",;,",))}, "where lower(Col1) contains lower('"&$F$1&"') or lower(Col1) contains lower('"&$G$1&"') or Col1 contains 'Timestamp'"), ",")))
Basically, what the formula does step by step is:
It appends a column that marks the end of the row when we combine them into 1 column.
Combines all columns into 1 using , as delimiter (, marks per column and ; marks per row)
Then we split them by ,;, to separate each rows (each row contains the textjoined result)
After that, we filter the data using query where a row should contain the values of F1 and G1 (and including Timestamp to include the header).
Filtered data will then split back to their original form
Output:
EDIT:
To be dynamic, I modified it to check F1:1 range instead.
Formula:
=if(E1="",
QUERY(IMPORTRANGE("Spreadsheetidabcd", "RawData!A:Z"), "Select Col1,Col12,Col2,Col10,Col3 where (Col11='')",1),
arrayformula(split(query({transpose(split(textjoin(",", true, QUERY(IMPORTRANGE("Spreadsheetidabcd", "RawData!A:Z"), "Select Col1, Col12, Col2, Col10, Col3, ';' label ';' ';'")), ",;,",))}, "where lower(Col1) contains lower('"&join("') or lower(Col1) contains lower('", filter($F$1:$1, not(isblank($F$1:$1))))&"') or Col1 contains 'Timestamp'"), ",")))
Output:

How to append 3 tables with different number of columns in google sheet?

Hi everyone,
I have 3 tables with different number of columns where some columns are actually repeated in these 3 tables (as shown in the screenshot above).
Table 1: Col A to Col D
Table 2: Col F to Col H
Table 3: Col J to Col L
I want to merge these 3 tables together to reduce the number of columns in my google sheet. The screenshot below is how I process these 3 tables before merging.
I'm using QUERY to create extra columns for each table so that the number of columns and the position are aligned between 3 tables. After that, I use QUERY again to append the 3 processed tables as shown in the screenshot below:
However, this method is very tedious when I have 10 tables or more. Is there any other easier ways or tricks to use so that I can achieve the same expected output as shown in the 3rd screenshot?
This is my sheet:
https://docs.google.com/spreadsheets/d/1H1gJAhp1RVax2fy8D-uEtFxdjb-zAHutkPFv5WZT_TY/edit#gid=0
Any help will be greatly appreciated!
You would need a really complicated formula to get the desired output which is a combination of multiple formula's
I added a new tab in you Google Sheet called "Solution" with this formula included
=QUERY(ARRAYFORMULA({
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!B3:D3&"~"&Sheet1!A4:A&"~"&Sheet1!B4:D),"~")),"");
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!G3:H3&"~"&Sheet1!F4:F&"~"&Sheet1!G4:H),"~")),"");
IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!K3:L3&"~"&Sheet1!J4:J&"~"&Sheet1!K4:L),"~")),"")}),
"SELECT Col2, SUM(Col3) WHERE Col2 is not null GROUP BY Col2 PIVOT Col1 LABEL Col2 'Student Name' ")
Steps:
Unpivot each table =IFERROR( ArrayFormula(SPLIT(FLATTEN(Sheet1!B3:D3&"~"&Sheet1!A4:A6&"~"&Sheet1!B4:D6),"~")),"")
Combine all tables into one table: =ARRAYFORMULA({__Unpivot1__; __Unpivot2__, __Unpivot3__})
Pivot above data in Step2: =Query(__Step2__, "SELECT Col2, SUM(Col3) GROUP BY Col2 PIVOT Col1 LABEL Col2 'Student Name' ")
Add WHERE Col2 is not null in the query to remove any possible blank rows

Split each row in a column whose value contains commas into transposed rows

So I have data in the following format:
I want to summarize this into another sheet like this:
So I can use TRANSPOSE(SPLIT(A1:A)) to do this individually
I can use ARRAYFORMULA(SPLIT(A:A)) to run this over a range, however I cant seem to use both of them together to the same effect
To summarize
Column A contains comma seperated values for car names
I want to get all the car names as rows in another sheet and add counts against them
You can get the whole mini-report with this one formula:
=ArrayFormula(QUERY(FLATTEN(TRIM(SPLIT(A2:A,","))),"Select Col1, COUNT(Col1) Where Col1 > '#' GROUP BY Col1 LABEL COUNT(Col1) ''"))
SPLIT will split every entry in A2:A at the comma (if there is one) and will result in an error for every blank row (dealt with later).
TRIM removes the spaces after any comma-splits.
FLATTEN creates one column from all results (words, blanks and errors).
QUERY(...,"Select Col1, COUNT(Col1) Where Col1 > '#' GROUP BY Col1 LABEL COUNT(Col1) ''") starts with everything in that FLATTEN column and a COUNT of each GROUPed by the name ruling out anything WHERE the value in Col1 is not > the '#' symbol (which will rule out all blanks and errors). Finally, LABEL will get rid of the superfluous header of "count" that would otherwise be generated for the COUNT(Col1) column of the QUERY.
Alternatively, you could rule out the errors first with a FILTER and then use the WHERE part of the QUERY to rule out blanks:
=ArrayFormula(QUERY(FLATTEN(TRIM(SPLIT(FILTER(A2:A,A2:A<>""),","))),"Select Col1, COUNT(Col1) WHERE Col1 Is Not Null GROUP BY Col1 LABEL COUNT(Col1) ''"))
Managed to solve it from this question
https://webapps.stackexchange.com/questions/114791/google-sheets-split-and-unique
=unique(transpose(arrayformula(trim(split(join(",",A1:A),",")))))
The most efficient is probably QUERY. Unlike JOIN, this has no limit on the number of characters in the result.
Basic approach
=ARRAYFORMULA(TRANSPOSE(SPLIT(
QUERY(A:A&",",,9^9),
", "
)))
Unique
=ARRAYFORMULA(UNIQUE(TRANSPOSE(SPLIT(
QUERY(A:A&",",,9^9),
", "
))))
Counting the number in a group
=ARRAYFORMULA(QUERY(
TRANSPOSE(SPLIT(QUERY(A:A&",",,9^9),", ")),
"select Col1, count(Col1) group by Col1 label count(Col1)''"
))

Combining values ​based on conditions, using an Arrayformula | Google Sheets

What should a function that combines selected values ​​into one using an array function look like?
I would like the function to combine Unique Nr if Id and data are the same.
https://docs.google.com/spreadsheets/d/1x1yR2oc2VxUFuijEq-bhLKGgHscnIzDVS0cguIslajk/edit?usp=sharing
try:
=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(FLATTEN(
QUERY(QUERY({A2:A&","\ B2:B&" "&C2:C&"♦"};
"select max(Col1)
where Col1 <> ','
group by Col1
pivot Col2");; 9^9)); "♦")); ",$"; ))

Grouping by Name in Query Formula not working

So I am using a query function to count the number of instances a particular name appears in column A of another sheet, and display that result in Column B of this sheet with the respective name in Column A. Here is the function:
=ArrayFormula(QUERY(Attendance!A:A&{"",""},"select Col1, count(Col2) where Col1 != '' group by Col1 label count(Col2) 'Count'",1))
The problem is, while it works for the most part, some of the names appear twice, for instance Fred Jones appears as:
Col A | Col B
Fred Jones | 5
Fred Jones | 2
I have looked at the names, and there is no discernible difference between them, I do not understand why it is not grouping. Is there a way I can use wildcard or something to get Google to combine the names if they are nearly identical? Any help would be appreciated, thanks as always.
try:
=ARRAYFORMULA(QUERY(TRIM({Attendance!A:A}),
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)'Count'", 1))

Resources