Combine first column of n sheets to one colume - google-sheets

So in one spreadsheet file we have n sheets.
Sheet1
Names
a
b
Sheet2
Names
b
c
d
and so on.. assume n sheets with n values in the first column
Then there's one super sheet.
Super sheet
Supersheet
Supersheet
Supersheet
Supersheet
Sheet1
Sheet2
Sheet3
...
Names
Count
a
1
b
2
c
1
d
1
Assume A1:1 is a list of all of the names of the sheets we want to fetch names from. We want the names pasted into A3:A.
My first thought was to do
=unique(filter({INDIRECT(A1&"!A3:A");INDIRECT(B1&"!A3:A");INDIRECT(C1&"!A3:A")},{INDIRECT(A1&"!A3:A");INDIRECT(B1&"!A3:A");INDIRECT(C1&"!A3:A")}<>""))
and expand, but that doesn't take care of N sheets.
So what I thought I could do was
=ARRAYFORMULA(INDIRECT(A2:C2&"!A2:A3"))
but that only takes care of sheet1. INDIRECT doesn't work with arrayformula
So what can I do?

you can either use some script or put your sheets in array {} and pre-program it:
=QUERY({INDIRECT(Sheet1!A1&"!A3:A");
INDIRECT(Sheet2!A1&"!A3:A")},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''")
since this is one column future sheets can be added this way:
=QUERY({INDIRECT(Sheet1!A1&"!A3:A");
INDIRECT(Sheet2!A1&"!A3:A");
IFERROR(INDIRECT(Sheet3!A1&"!A3:A"));
IFERROR(INDIRECT(Sheet4!A1&"!A3:A"))},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''")
IMPORTRANGE would be:
=QUERY({IMPORTRANGE("id", Sheet1!A1&"!A3:A");
IMPORTRANGE("id", Sheet2!A1&"!A3:A");
IFERROR(IMPORTRANGE("id", Sheet3!A1&"!A3:A"));
IFERROR(IMPORTRANGE("id", Sheet4!A1&"!A3:A"))},
"select Col1,count(Col1)
where Col1 is not null
group by Col1
label count(Col1)''")
ofc, every importrange formula needs to be authorized separately

Related

How to get unique values in a column, including cells with multiple values seperated by commas, in Google Sheet?

I have a column in a Google Sheet, which in some cases, includes multiple values separated by commas — like this:
Value
A example
B example
C example
D example
A example, E example
A example, F example
G example, D example, C example
I would like to count all occurrences of the unique values in this column, so the count should look like:
Unique value
Occurrences
A example
3
B example
1
C example
2
D example
2
E example
1
F example
1
G example
1
Currently, however, when I use =UNIQUE(A2:A), the result gives this:
Unique value
Occurrences
A example
1
B example
1
C example
1
D example
1
A example, E example
1
A example, F example
1
G example, D example, C example
1
Is there a way I can count all of the instances of letters, whether they appear in individually in a cell or appear alongside other letters in a cell (comma-seperated)?
(This looks like a useful answer in Python, but I'm trying to do this in Google Sheets)
try:
Formula in C1:
=INDEX(QUERY(IFERROR(FLATTEN(SPLIT(A1:A,", ")),""),"Select Col1, count(Col1) where Col1 is not null group by Col1 label count(Col1) ''"))
Or, as per the comments, split on the combination instead:
=INDEX(QUERY(IFERROR(FLATTEN(SPLIT(A1:A,", ",0)),""),"Select Col1, count(Col1) where Col1 is not null group by Col1 label count(Col1) ''"))
2nd EDIT: To order descending by count use:
=INDEX(QUERY(IFERROR(FLATTEN(SPLIT(A1:A,", ",0)),""),"Select Col1, count(Col1) where Col1 is not null group by Col1 Order By count(Col1) desc label count(Col1) ''"))
Assuming data in A1:A7:
In C1:
=SORT(UNIQUE(FLATTEN(ARRAYFORMULA(SPLIT(A1:A7,", ")))))
In D1:
=ARRAYFORMULA(MMULT(0+ISNUMBER(SEARCH(", "&ColumnCSpilledRange&", ",", "&TRANSPOSE(A1:A7)&", ")),ROW(A1:A7)^0))
Replace ColumnCSpilledRange appropriately.

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

Need to know with formula in Google sheet

I have date in column A, Name in column B and Product sale data in column C. Now I want formula which gives me in return in another table, If that person has sold something on a particular date that sale data entry is shown
Do it with a pivot table so that you will have the answer without any formula.
Try query() with a pivot clause, like this:
=query(A1:C, "select A, B, count(B) where A is not null group by A, B pivot C", 1)
May be it can help too
=Query('Sales '!A1:C, "Select Col1, Col2, Col3 Where Col3 is not null",0)
'Sales ' is data source worksheet
use ,1 if you don't want to include the same headers of of your data source worksheet

How can I avoid having to put 0s into the NULL fields to get a correct query calculation in Google Sheets

I have a Google Sheets question, which I have not been able to figure out yet with Google-Fu and RTFM:
Take the following spreadsheet as an example:
https://docs.google.com/spreadsheets/d/1IvMVaUdUDfYOoKyG0Uwd2n0M1mLjOTE5yZQ9K2R3q2M/edit?usp=sharing
In case the sheet gets lost in time, I am going to post its contents here:
Sheet1:
foo
withdrawal
deposit
C
4
10
D
10
E
10
4
As you see here, the withdrawal field for the D value being foo is empty, i.e. null
Sheet2:
foo
balance
C
=INDEX(QUERY({Sheet1!$A$2:C}, "SELECT SUM(Col3) - SUM(Col2) WHERE Col1 = '"&A2&"'"), 2)
D
=INDEX(QUERY({Sheet1!$A$2:C}, "SELECT SUM(Col3) - SUM(Col2) WHERE Col1 = '"&A3&"'"), 2)
E
=INDEX(QUERY({Sheet1!$A$2:C}, "SELECT SUM(Col3) - SUM(Col2) WHERE Col1 = '"&A4&"'"), 2)
The result is
foo
balance
C
6
D
E
-6
As you see, the balance field for the category D is null, although it should be -10.
The fix for that is to put a 0 into the deposit field in Sheet1 explicitly.
In my example, I get that data using a csv-export, and fields are generally empty and not 0, and it is cumbersome to add the 0 there. Is there a way to have something like COALESCE in that sum there (like in SQL)?
Please let me know.
it seems like something quite a bit simpler would avoid the problem:
=SUMPRODUCT(Sheet1!C:C-Sheet1!B:B,Sheet1!A:A=A2)
for cell B2.
Why don't you just add this in cell A1 of Sheet2 instead of all the Query:
=arrayformula({Sheet1!A1,"balance";if(Sheet1!A2:A<>"",{Sheet1!A2:A,Sheet1!C2:C-Sheet1!B2:B},)})
Obviously ensure cells Sheet2!A2:A and Sheet2!B1:B are empty.
If you have duplicate values of foo, try:
=arrayformula(query({Sheet1!A1,"balance";if(Sheet1!A2:A<>"",{Sheet1!A2:A,Sheet1!C2:C-Sheet1!B2:B},)},"select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col2) 'balance'",1))
A better option for a single-cell formula, referencing multiple sheets would be:
=arrayformula(query(
{Sheet1!A:A,n(Sheet1!B:C);Sheet2!A2:A,n(Sheet2!B2:C);Sheet3!A2:A,n(Sheet3!B2:C)},
"select Col1,sum(Col3)-sum(Col2) where Col1 is not null group by Col1 label sum(Col3)-sum(Col2) 'balance' ",1))

Setting up Google sheets formula

I have a sheet that has 2 columns - id and comment. In a new sheet I need a formula that is set up like the following: First column is the id, the second column is the frequency of the id and the third column is a list of all the comments associated with that id.
Currently I got the first two columns working with the following formula but don't know how to add the third column (list of comments):
=ArrayFormula(QUERY(IF({1,1},TRANSPOSE(SPLIT(CONCATENATE('Oct. 2017'!C:C&CHAR(9)),CHAR(9))))&"","select Col1, count(Col2) group by Col1 order by count(Col2) desc label Col1 'ID', count(Col2) 'Frequency'",0))
Assuming your formula populates A1 onwards and your sheet with two columns is called Oct. 2017 please try in C1 and copied down to suit:
=join(", ",filter('Oct. 2017'!D:D,'Oct. 2017'!C:C=A1))

Resources