issue with querying of multiple tabs inside same sheet - google-sheets

i am trying to query number of response, country name and month from one tab but i also need it to display the name of country corresponding to country number which is in a different tab
this is my statement
=QUERY({CSAT!$A$2:$F$34;Countries!$A$2:$B$11},"SELECT Col1, Col2, Col3, Col5 WHERE Col1 = 'Jun-21' ON Col2 = Col3 ")
i keep getting an error saying that there are missing values on lateral array

Number of columns from both sheets must be the same if you want to append them in the query. Using the query with different number of columns (6 vs 2) will result into:
If we get 2 columns from both sheets:
=QUERY({CSAT!$A$2:$B$34;Countries!$A$2:$B$11})
Error is not shown:

Related

Google sheet query select column from different spreadsheet

I have this query:
=Query({'Sheet request '!A2:Q;'Sheet sent '!A2:Q},"Select Col1,Col2,Col4,Col3 Where Col1 is not null",1)
How I am going to add this query so that I can have the column 12 from tab genseat?
=Query({genseat!A2:O},"Select Col12 Where Col1 is not null",1)
Since your first query generates 4 columns, you can only append a second query if you also generate 4 columns.
If you want 3 static columns of data in the second query, you could use something like:
=Query({genseat!A2:O},"Select Col12,'value1','value2','value3' Where Col1 is not null label 'value1' '','value2' '','value3' '' ",1)
Then you can add your queries together using {query1;query2} and put a third query around them to bring back records that are not null:
query({query1;query2},"where Col1 is not null",1)

How to find the most frequent text value in a whole spreadsheet on Google sheets?

I know the code to find the most frequent value in a single column, but I'm trying to figure out the code that lets me find the most frequent value in multiple specific columns.
For example:
=ARRAYFORMULA(INDEX(A2:A17,MATCH(MAX(COUNTIF(A2:A17,A2:A17)),COUNTIF(A2:A17,A2:A17),0)))
^^this formula only allows me to have two arguments for COUNTIF
=INDEX(A2:A6,MODE(MATCH(A2:A6,A2:A6,0)))
^^this one only allows 4 arguments max in the index
I want an equation that'll allow me to find the most frequent text value for 16 specific columns.
Is that even possible?
BETTER FORMULA
You asked for formula when you have 2 top values with the same frequency
=SORTN(QUERY(FLATTEN(H2:K),
"select Col1, count(Col1)
where Col1 is not null group by Col1
order by count(Col1) desc label count(Col1) '' ",0),1,1,2,0)
First answer
Use only 1 QUERY formula
For top value
=QUERY(FLATTEN(A2:D),
"select Col1, count(Col1)
where Col1 is not null group by Col1
order by count(Col1) desc limit 1",0)
For all values
=QUERY(FLATTEN(A2:D),
"select Col1, count(Col1)
where Col1 is not null group by Col1
order by count(Col1) desc limit 1",0)
I show it in 2 steps then combine steps together in one formula:
First you flatten table and remove duplicates to get a column of values you check frequency for:
unique(flatten(B2:I25))
Then for each one you check number of occurences:
ArrayFormula(countif($B$2:$I$25,unique(flatten(B2:I25))))
Then you have to filter new table and get only rows with highest values:
=filter({first , second column};second column = max(second column)
Using earlier values:
=filter({unique(flatten(B2:I25)),ArrayFormula(countif($B$2:$I$25,unique(flatten(B2:I25))))},ArrayFormula(countif($B$2:$I$25,unique(flatten(B2:I25))))=max(ArrayFormula(countif($B$2:$I$25,unique(flatten(B2:I25))))))
My solution is available here:
https://docs.google.com/spreadsheets/d/1gMZDFWOY8qbA1Bhp8rZ_por3Skb0i_qQtlaSlCTKXgM/copy
If your columns are scattered around your sheet, you should use { } and make a table of them.

Filter IMPORTHTML data

When I import data, it comes in this format (image 1), with blank spaces. I would like to know if there is any way to adjust so that these blanks disappear, the two models expected (image 2 and 3) if there was any way to reach them would be important to me.
Remembering that all dates have / and all times have :
I tried to filter from QUERY, but when trying to "Select Col1, Col2, Col4 Where Col2 is not null" the dates disappear and only the times remain, I tried via REGEXMATCH to separate the dates from the times using / and : but also I was not successful.
I also tried it via IMPORTXML, but some data ends up not being imported correctly on some pages of the site, for IMPORTHTML these errors do not happen. The XML's I used were:
"//tr[#class='no-date-repetition-new' and ..//td[#class='team team-a']] | //tr[#class='no-date-repetition-new live-now' and ..//td[#class='team team-a']]"
"//td[#class='team team-a']/a | //td[#class='team team-a strong']/a"
The current formula is as follows:
=IMPORTHTML("https://int.soccerway.com/national/austria/1-liga/20192020/regular-season/r54328/","table",1)
IMPORTHTML Original:
Expected formats:
---
Rather than filtering what you need is to restructure the imported data.
Anyway, I think that the easier solution to get the final result is to use multiple IMPORTXML formulas.
URL
A1: https://int.soccerway.com/national/austria/1-liga/20192020/regular-season/r54328/
Headers
A2: //table[contains(#class,'matches')]/thead/tr/th
Day
A3: //td[contains(#class,'date')]/parent::tr
Teams and Score
A4: //td[contains(#class,'team-a')]/parent::tr
A6: =transpose(IMPORTXML($A$1,A2))
A7: =IMPORTXML($A$1,A3)
B7: =IMPORTXML(A1,A4)
You might want to replace the formula on A6 by static values in order to place them properly.
You can join 2 queries together (one next to the other) in a single formula, to get your results
={QUERY(IMPORTHTML("https://int.soccerway.com/national/austria/1-liga/20192020/regular-season/r54328/","table",1),
"select Col1 where Col2 is null and not Col1 contains '*'",1),
QUERY(IMPORTHTML("https://int.soccerway.com/national/austria/1-liga/20192020/regular-season/r54328/","table",1),
"select Col1, Col2, Col3, Col4 where Col2 is not null label Col1 'Time'",1)}
How the formula works:
As you notice the data part of both queries is the same in both of them. What is actually different is "what we ask for from the query"
In the first one we use "select Col1 where Col2 is null and not Col1 contains '*'"
In the second one "select Col1, Col2, Col3, Col4 where Col2 is not null label Col1 'Time'"
We create an array by joining them together as in ={1stQUERY,2ndQUERY}

Include a specific cell in an array query Google Sheets

I have an array query that runs across multiple sheets in a Google Doc. The query works fine, but I would like to know the sheet of each data returned. I made an example HERE . the formula is :
=QUERY({Sheet2!A2:B6; Sheet3!A2:B6}, "select Col1, Col2 where Col2 = 'Y'")
When a 'Y' is found, I want to return the Data in Col1, Col2 AND (this is the part I don't know how to do) the value of A1 on the page where the match occured.
You can insert page title in the array as its third column, and select that column with the query:
=arrayformula(query({Sheet2!A2:B6, iferror(Sheet2!A2:A6/0, Sheet2!A1); Sheet3!A2:B6, iferror(Sheet3!A2:A6/0, Sheet3!A1)}, "select Col1, Col2, Col3 where Col2 = 'Y'"))
Here, iferror(Sheet2!A2:A6/0, Sheet2!A1) is a clumsy but effective way of saying: take the shape of array Sheet2!A2:A6/0 and fill it with the content of the cell Sheet2!A1. This results in the page title being repeated in every row taken from that sheet (provided that arrayformula wrapper is present, so that the computation /0 is performed with the array). The query returns
Data 2 on page 2 Y Page 2 Title
Data 4 on page 2 Y Page 2 Title
Data 2 on page 3 Y Page 3 Title

How do I find the second MODE in google spreadhseet

I have a list of numbers and I am using =MODE to find the number which appears most often, my question is how do I find the second most often occurring number in the same list?
In Google Sheets, you can use the QUERY function to retrieve this sort of information (and much more) quite easily. Assuming your data is numerical values only in column A with no header:
=QUERY({A:A,A:A},"select Col1, count(Col2) where Col1 is not null group by Col1 order by count(Col2) desc",0)
will return a list of the items in column A, and their associated frequencies, sorted from highest to lowest. Note: if column A contains text strings, you need to use where Col1 != '' rather than where Col1 is not null.
Now you can use INDEX to retrieve the exact value you require; so to retrieve the second most frequent value, you need the third value in the first column (as QUERY will populate a header row in the output):
=INDEX(QUERY({A:A,A:A},"select Col1, count(Col2) where Col1 is not null group by Col1 order by count(Col2) desc",0),3,1)

Resources