I have a Google Sheets document with four sheets. In each sheet, there are two columns: first is a name, and second a value.
I need to get the total of the values from the four sheets in a fifth sheet where the names from the four name-columns correspond.
The column with the values is called differently in most sheets.
How can I accomplish this task?
You can use Query + Arrays, like on image below:
Code:
=QUERY({Sheet1!A2:B;Sheet2!A2:B;Sheet3!A2:B;Sheet4!A2:B};
"select Col1,sum(Col2) where Col1 is not null group by Col1 label Col1 'Name',sum(Col2) 'Total'";0)
Explanation:
First: you combine 4 sheets using an Array. Ranges start from row 2 to omit different columns headers:
{Sheet1!A2:B;Sheet2!A2:B;Sheet3!A2:B;Sheet4!A2:B}
Second: Using Query to perform a total. In Query there are some extra operations:
Col1 is not null - for not showing empty rows in totals
label Col1 'Name',sum(Col2) 'Total' - for naming result columns
Syntax may be a little different depending on your local settings, so look at the working copy:
Link to working copy
Is that serves your needs?
Related
How can I combine 2 spreadsheets into one without any gaps? When I import range 2 sheets, there is a gap of ~1000 rows. To make sure there are no gaps between the 2 sheets, I usually create a query "Where Col1 is not null " but I am missing some info. :(
My spreadsheet: https://docs.google.com/spreadsheets/d/1aSnbySwNPEvkkXqw6ItuBpZ_6-o58HPlVicIHWD0Y4I/edit#gid=381064131
Thanks in advance.
You can use just being three columns:
=query({
importrange("https://docs.google.com/spreadsheets/d/1aSnbySwNPEvkkXqw6ItuBpZ_6-o58HPlVicIHWD0Y4I/edit#gid=0", "Sheet1!A2:C");
IMPORTRANGE("https://docs.google.com/spreadsheets/d/1aSnbySwNPEvkkXqw6ItuBpZ_6-o58HPlVicIHWD0Y4I/edit#gid=0", "Sheet2!A2:C")}, "Select * WHERE Col1 IS NOT NULL OR Col2 is not null OR Col3 is not null")
A second possible scenario for avoiding empty rows, no matter how many columns you have is wrapping your range or query in LAMBDA, and use FILTER associated with BYROW and COUNTA. If there are no elements in any row, then the count will be 0 and it will be filtered out:
=LAMBDA(quer,FILTER(quer, BYROW (quer, LAMBDA (each,COUNTA(each)))))({
importrange("https://docs.google.com/spreadsheets/d/1aSnbySwNPEvkkXqw6ItuBpZ_6-o58HPlVicIHWD0Y4I/edit#gid=0", "Sheet1!A2:C");
IMPORTRANGE("https://docs.google.com/spreadsheets/d/1aSnbySwNPEvkkXqw6ItuBpZ_6-o58HPlVicIHWD0Y4I/edit#gid=0", "Sheet2!A2:C")})
Both solutions return:
I got data as follows:
I need a formula that can separate, list and the count each unique word so my output is:
I am pretty new to google sheet formulas, especially combining several together. Thanks in advance.
Suppose the header "Genre" is in A1 with your comma-separated list running down from A2.
Find two empty columns side by side and place the following in the top cell of the leftmost of those two empty columns:
=ArrayFormula(QUERY(FLATTEN(TRIM(SPLIT(FILTER(A2:A,A2:A<>""),","))),"Select Col1, COUNT(Col1) WHERE Col1 Is Not Null GROUP BY Col1 ORDER BY COUNT(Col1) DESC LABEL Col1 'Genre', COUNT(Col1) 'Total'"))
FILTER will cut null cells from A2:A, leaving you only with populated cells.
SPLIT will split each cell into separate columns at the commas.
TRIM will remove leading spaces that existed after commas.
FLATTEN will form one column from the results of SPLIT.
QUERY will give you the unique names and COUNT for each in highest-to-lowest (DESCending) order of COUNT (with a default of alphabetizing within groups of equal counts) after eliminating any null results of FLATTEN and will assign meaningful headers (LABELs) to each column.
I have two columns of text/abbreviations i want to summarize in a (or two respectively) tables.
Example:
Column 1: SiteScopeInput
Swap_G09+Remove_U21+Rollout_L07+Swap_L08+Swap_L18+Rollout_L21+Rollout_N35
Remove_U21+Rollout_L07+Swap_L08+Swap_L18+Rollout_L21+Rollout_N35
Swap_G09+Rollout_L07+Swap_L08+Swap_L09+Swap_L18+Rollout_L21+Swap_L26+Rollout_N35
Swap_G09+Remove_U21+Rollout_L07+Swap_L08+Swap_L18+Rollout_L21+Rollout_N35
Here I'd like to summarize how many times words occure - for example:
Swap_G09
Remove_U1
Rollout_L07
and so on.
I've tried a combination of
ArrayFormula, LEN and REGEXREPLACE
but my beginner mind can't wrap around this task.
Any tips? Thanks!
If you want to treat Swap_G09 etc. as a separate word, then a combination of split, flatten and query should do it:
=ArrayFormula(query(FLATTEN(split(filter(A:A,A:A<>""),"+")),"select Col1,count(Col1) where Col1 is not null group by Col1 label Col1 'Word'"))
I have searched on a lot of pages but I cannot find a solution to my problem except in reverse order. I have simplified what I do, but I have a query that comes looking for information in my data sheet. Here there are 3 columns, the date, the amount and the source.
I would like, with a query function, to be able to make different columns which counts the information of column C based on the values of its cells per month, like this
I'm okay with the start of the formula
=QUERY(A2:C,"select month(A)+1, sum(B), count(C) where A is not null group by month(A)+1")
But as soon as I try a little different things by putting 2 query together in an arrayformula, obviously the row count doesn't match as some minus are 0 for some sources.
Do you have a solution for what I'm trying to do? Thank you in advance :)
Solution:
It's not possible in Google Query Language to have a single query statement that has one result grouped by one column and another result grouped by another.
The first two columns can be like this:
=QUERY(A2:C,"select month(A)+1, sum(B) where A is not null group by month(A)+1 label month(A)+1 'Month', sum(B) 'Amount'")
To create the column labels for the succeeding columns, use in the first row, in my example, I1:
=TRANSPOSE(UNIQUE(C2:C))
Then from cell I2, enter this:
=COUNTIFS(arrayformula(month($A$2:$A)),$G2,$C$2:$C,I$1)
Then drag horizontally and vertically to apply to the entire table.
Results:
try:
=INDEX({
QUERY({MONTH(A2:A), B2:C},
"select Col1,sum(Col2) where Col2 is not null group by Col1 label Col1'month',sum(Col2)'amount'"),
QUERY({MONTH(A2:A), B2:C, C2:C},
"select count(Col3) where Col2 is not null group by Col1 pivot Col4")})
I am using a query formula to import data from a different sheet.
However after querying the data, I got the same code which I need to sum the episode and the value with unique formula therefore after querying only show unique code. I'm not sure how to mix the formula.
My query formula is the following:
=QUERY(Paste!A:M,"SELECT A,B,C ORDER BY C DESC LIMIT 15")
My spreadsheet link is the following:
https://docs.google.com/spreadsheets/d/1A6lGIlU147Y_0WFD7Btkq4IMuY-Z3D1HsNiTgjLjm0o/edit?usp=sharing
As above image. Under column A I have same code for FMEM1 due to my raw data separate it for some reason. I don't want the same code separated. I want unique code not separated and sum the episode and sum the value
try
=query({A3:A17,B3:B17,C3:C17},"select Col1, Sum(Col2),Sum(Col3) group by Col1 label Col1 'Code',Sum(Col2) 'Total Episode',Sum(Col3) 'Total Value'")
Screenshot