I have data in two sheets (Source Sheet and Result Sheet). I want to import the unique values based on two columns of the source sheet into result sheet along with the product of two columns based on unique value. For more clarity I had entered test data in the Source Sheet with the expected outcome in the Result Sheet. The links of both the sheets are as below
Source sheet https://docs.google.com/spreadsheets/d/13biwAB46kswhIIiLnO-Nn9B8Vf5AAPghsY9YZrYJ470/edit#gid=0
Result Sheet https://docs.google.com/spreadsheets/d/1p9ejduRsFxxDA7vgnO0Y9Wt8Vc9Kwb-gSlhoW1T-ESo/edit#gid=0
Any help on above will be greatly appreciated.
Use nested QUERY() function with IMPORTRANGE().
=QUERY(QUERY(
IMPORTRANGE("13biwAB46kswhIIiLnO-Nn9B8Vf5AAPghsY9YZrYJ470","Sheet1!A2:D"),
"select Col1, Col2, Col3*Col4
label Col3*Col4 ''"),
"select Col1, Col2, sum(Col3)
group by Col1, Col2
label sum(Col3) ''")
If you use E Column in source sheet then you can use only one query-
=QUERY(
IMPORTRANGE("13biwAB46kswhIIiLnO-Nn9B8Vf5AAPghsY9YZrYJ470","Sheet1!A2:E"),
"select Col1, Col2, sum(Col5)
where Col5 is not null
group by Col1, Col2
label sum(Col5) ''")
Related
I am trying to query two columns of data in Google Sheets and count how many times the values occur.
I have made a Google Sheets formula which works but only returns data in the first column.
=QUERY(QUERY({D2:D,E2:E}, "select Col1, count(Col1) group by Col1"), "select Col1, Col2 order by Col2 desc, Col1 limit 45", 0)
How can I query and count data from both columns together?
DESIRED RESULT
2.38 / 2
5.38 / 2
...
I have made a Google Sheet showing an example. This can be copied by going to File-Make a Copy
https://docs.google.com/spreadsheets/d/1S5fE43JPVgUhZFVx-rjowkCy8N6p_ziIhIWe4MweiXQ/edit?usp=sharing
If your formula gives the correct output, you may need to change your comma with semicolon. That way all your data will be grabbed as a single column:
=QUERY(QUERY({D2:D;E2:E}, "select Col1, count(Col1) group by Col1"), "select Col1, Col2 order by Col2 desc, Col1 limit 45", 0)
Please try:
=QUERY({D2:D;E2:E},"Select Col1, COUNT(Col1) WHERE Col1 IS NOT NULL GROUP BY Col1 ORDER BY COUNT(Col1) DESC LABEL COUNT(Col1)''")
I am trying to calculate a count of how many times a course is listed in different columns and return the count in a list of all the courses found in those columns.
I have a spreadsheet that shows the start of my formula...
query(UNIQUE({C2:C21; F2:F21;I2:I21}),"select C,F,I, count(C), count(F), count(I) where B is not null group by C,F,I")
Clear cells A23, A24 and B23 and then try in A23
=query({C2:C21; F2:F21;I2:I21},"select Col1, count(Col1) where Col1 <> '' group by Col1 label Col1 'Fall Courses', Count(Col1) 'Count'")
and see if that helps?
If it does, you can repeat the same logic for 'winter' and 'spring'.
Alternatively, you can also try this single formula
=query(ArrayFormula(split(transpose(split(textjoin("~", true, regexreplace(C1:K1, "(Winter|Spring|Fall)", "_$1")&"_"&C2:K21), "~")), "_")), "Select Col3, Count(Col3) where Col3 <>'' group by Col3 pivot Col2", 0)
I have the following example spreadsheet: https://docs.google.com/spreadsheets/d/1uv0Lj5sayraH4FOPE1qZ3coLA9A2incLuX2JYD5y7SQ/edit?usp=sharing
I have a query on Sheet 2 that references sheet1 and sheet2. I would like to have the query return 3 columns, Name, ID, and GroupName. GroupName should reference A1 from the sheet.
I cannot find a way to do this, but it seems that it should be possible.
Something like
=query({Sheet1!A:B; Sheet2!A:B},"Select Col1, Col2, A1 Col3 where Col1 is not null")
Try:
=arrayformula(query({iferror(Sheet1!A2:A/0,Sheet1!A1),Sheet1!A2:B; iferror(Sheet2!A3:A/0,Sheet2!A1),Sheet2!A3:B},"where Col2 is not null label Col1 'GroupName'",1))
You can alter the column order like this (select Col2, Col3, Col1):
=arrayformula(query({iferror(Sheet1!A2:A/0,Sheet1!A1),Sheet1!A2:B; iferror(Sheet2!A3:A/0,Sheet2!A1),Sheet2!A3:B},"select Col2, Col3, Col1 where Col2 is not null label Col1 'GroupName'",1))
I was able to get it to work by swapping the semi-colon for a comma
=query({Sheet1!A:B, Sheet2!A:B},"Select Col1, Col2, Col3 where Col1 is not null")
Col3 should be col A from sheet2
I have a data set with multiple columns and roughly 1000 rows. I need to find out how many times certain combinations of columns can be found within the data set.
In my example below, columns A:B represents the raw data set. In C2 I have a formula that finds all non-unique combinations from columns A:B. What I need is a formula that counts how many times combinations in columns C:D are found within columns A:B. The desired output should be in ColE.
you can do it all in one go... delete columns C, D, E and use this formula:
=ARRAYFORMULA(QUERY({A2:B, A2:A&B2:B},
"select Col1,Col2,count(Col3)
where Col1 is not null
group by Col1,Col2
order by count(Col3) desc
label count(Col3)''"))
for a selected combination only use this formula in E2 cell:
=ARRAYFORMULA(IFERROR(VLOOKUP(C2:C&D2:D, QUERY({A2:A&B2:B},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''"), 2, 0)))
It's always better to share a copy of your spreadsheet, but try entering in E1
={"Count"; ArrayFormula(IF(LEN(C2:C), VLOOKUP(C2:C&D2:D, query({A2:A&B2:B, A2:B}, "Select Col1, count(Col3) where Col1 <>'' group by Col1"), 2, 0),))}
and see if that works?
Note that you can create the same output (columns C, D and E) with a single formula
=query(ArrayFormula(query({A2:B, A2:A&B2:B}, "Select Col1, Col2, count(Col3) where Col1 <>'' group by Col1, Col2")), "where Col3 >1 label Col1 'Value 1', Col2 'Value 2'")
I've been having troubling getting the query function to return 0 when the queried data isn't found.
Given the following data...
With each sheet being a different player, I need to count the number of games each played and the outcome of those games.
Some players may be in the same game as each other so the gameIDs are given as a unique identifier so those games are only counted once, that part I have working.
What I'm trying to do now is record the number of wins team A has in each room.
You can see my problem in the above screenshot.
Here is the sample sheet that has the above data.
This is the formula used for the right most example
=QUERY({QUERY(UNIQUE(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 <> '' and Col3 contains 'A'")),"select Col1, 1");QUERY(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 = '' and Col1 <> '' and Col3 contains 'A'"),"select Col1, 1")},"select Col1, sum(Col2) where Col1 <> '' group by Col1 label sum(Col2) 'TeamA Wins', Col1 'Room'")
Anyone able to help?
You may add dummy data into the formula:
=QUERY(data;{QUERY(UNIQUE(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 <> '' and Col3 contains 'A'")),"select Col1, 1");QUERY(QUERY({Sheet1!A2:C;Sheet2!A2:C;Sheet3!A2:C},"select Col1, Col2 where Col2 = '' and Col1 <> '' and Col3 contains 'A'"),"select Col1, 1")},"select Col1, sum(Col2) where Col1 <> '' group by Col1 label sum(Col2) 'TeamA Wins', Col1 'Room'")
^^^^
data is a named range, it looks like this:
To make it:
paste the data to separate sheet, as shown in picture above.
select range A1:B6
go to Data → Named range → call it "data"
enter the formula and it should work fine now.
Sample file with working formula