How to add extra text to Query results? - google-sheets

I have a sheet with data that a Google Form is continually adding data to. Once the data is added, there is a subset that I need to have sectioned off to another sheet.
I'm transposing the data so it sorts vertically for each Form's data, and the problem I'm running into is that I want each vertical selection to be individually labeled with the same consistent labels and I don't think I can make CONCATENATE work in this case (I would love to be proven wrong!).
Here's a link to the sheet:
https://docs.google.com/spreadsheets/d/1efOQRlKaJlffMnLd8f8oPZxJ57wVFGwKwVY3UW0savc/edit?usp=sharing
Here's the formula I currently have in A1 on the 'Credential Request Form' sheet:
=TRANSPOSE(QUERY('Onboarding Form Responses'!A2:J,"Select F,B,C,D,G,A where A is not null order by A desc"))
This presents the data I want and in the order I want it, but without labels before the data (sorry, "label" might be the wrong word here). I've included an example of how I'd like the data to present in cells A9:A13 on the same sheet.
Is it possible to add those labels without a substantial amount of scripting?

No scripting needed.
You can use a similar formula for your needs:
=TRANSPOSE(query(ARRAYFORMULA({"Employee Name: "&'Onboarding Form Responses'!B2:B,
"Store Number: "&'Onboarding Form Responses'!F2:F,
"Parking Space: "&'Onboarding Form Responses'!G2:G}),
"Select Col1, Col2, Col3 where Col1 is not null order by Col1 desc"))
Notice that we use "Employee Name: "&'Onboarding Form Responses'!B2:B etc. for our ranges and then Col1, Col2, etc.

Related

How to SUMIF identical data spread out on multiple columns

I using excel to organize my cut list for a panel board. I have a table created like so, and i need help creating a formula that adds the number of pieces of panels of identical dimension and material, regardless of which panel it belongs
I have done formulas before where the datas where in a single column and there was only 1 criteria to check using UNIQUE and SUMIF formulas. I can already extract all the unique dimensions using
=UNIQUE(FLATTEN(C17:C19,E17:E19,G17:G19))
but that all that i got for now.
try:
={"Material", "Dimension", "Pcs";
QUERY({A2:C9; A2:A9, D2:E9; A2:A9, F2:G9},
"select Col1,Col2,sum(Col3) where Col1 is not null
group by Col1,Col2 label sum(Col3)''", 0)}

Attempting to Merge data and sum up the similar items. After a Filter/Sort within Google Sheets

Currently working on a project where im trying to Filter out and Sort out data from one list based on a dropdown menu. When the data gets pulled from the other list into a better readable format, it brings along some duplicate item names due to being listed seperately based on SKUS, is there any way i can SUM the total qunatities together, and have just 1 name within that list via Functions?
my current function is
=SORT(FILTER('Month of Detailed Manifest Report'!B2:D, 'Month of Detailed Manifest Report'!A2:A = A3, 'Month of Detailed Manifest Report'!B2:B <> "SAMPLES"),1,True)
Brings my data up like this.
You can see how it adds Duplicate Data Here
Just trying to get it so it merges the similar names and adds the Qty's together so i can get a better accurate data pull of information.
See my comment to your original post. That said, just eyeing it here and without the ability to test it, you can try this formula:
=QUERY({'Month of Detailed Manifest Report'!A2:D},,"Select Col2, Col3, SUM(Col4) WHERE Col1 = '"&A3&"' AND Col2 <> 'SAMPLES' GROUP BY Col2, Col3 LABEL SUM(Col4) '' ORDER BY Col2")
In theory, that should work.
If not, as I invited in my previous comment, share a link to a copy of the spreadsheet.

Only apply complex arrayformula() to rows with certain value in dataset

I have a quite complext formula (i mean that is complex to me) that Tom Sharpe helped me building to aggregate values and ordering them by months in a row(you can find the details in the original post but i think you'll only need the final formula which is:
=ArrayFormula(mmult(sequence(1,counta(A2:A),1,0), if((C2:index(C:C,counta(C:C))<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:index(D:D,counta(D:D))>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:index(E:E,counta(E:E)),0)))
and here is the result -> [J1:U1]
Now, what i would need to do as the final step is to be able to group data by a certain label (John or Jane in the example) on separate rows, but mantaining the order/aggregate by month on the row. On the example, this would mean having one row with only 'John' data and below, one with 'Jane' values.
I am struggling to understand how to adapt the formula to do so.
I have tried:
Using another array to first return a list of these labels with query(unique()) or something like that, but then i struggle looping in it with the other formula.
A bit more simplistic but it could work after all: on the 1st row (the cell next to where the data will be returned) writing 'John', on row 2 'Jane' and then using filter() to only pull data that matches. The 'John, Jane' value is for the example but the real labels won't be that many, the list of labels don't need to be dynamic.
The thing with these solutions is that they work when used separately, but i can't figure out how to nest this in the first arrayformula() that Tom helped me with...As i am just beginning with the google sheets queries.
I don't really need necessarily the complete formula/code but maybe just directions or tips to visualize the way i could solve this.
Thanks to all who might contribute
With hindsight I might have done better to go down the route of using a query to calculate the sums on my previous answer rather than Mmult.
This uses the same method as before to create a 2d array of amounts vs dates (going across) and individuals (going down). Then it uses Textjoin to generate a query to group by name with the required number of columns.
=ArrayFormula(query({A2:A,if((C2:C<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:D>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:E,0)},
"select Col1,sum(Col"&textjoin("),sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2))&") where Col1 is not null group by Col1"))
This is the generated query
select Col1,sum(Col2),sum(Col3),sum(Col4),sum(Col5),sum(Col6),sum(Col7),sum(Col8),sum(Col9),sum(Col10),sum(Col11),sum(Col12),sum(Col13) where Col1 is not null group by Col1
Ideally there should be an extra section saying label sum(Col2) '' etc. to suppress the 'Sum' headers.
=ArrayFormula(query({A2:A,if((C2:C<=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0)))* (D2:D>=eomonth(G2,sequence(1,datedif(G2,H2,"M")+1,0))),E2:E,0)},
"select Col1,sum(Col"&textjoin("),sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2))&") where Col1 is not null group by Col1 label sum(Col" & textjoin(") '', sum(Col",,sequence(1,datedif(G2,H2,"M")+1,2)) & ") ''"))

How to handle data manipulation when using importrange() in Google Sheets?

I am working on speeding up a workbook in Google sheets that is using importrange(). The purpose of the entire workbook is to import data from a mastersheet and then allow us to manipulate it the way we want to outside of the mastersheet.
The problem: because importrange() doesn't allow you to directly manipulate cells we have Sheet1 acting as the import sheet; it doesn't get touched. Sheet2 is where we do the manipulating but, it was literally just taken as a copy of Sheet1, so it is also using importrange(). This bogs down the entire workbook and makes manipulations very slow.
I am thinking of using !Sheet1A1... and copying that to all the cells in the manipulation sheet, but my concern is that this will still bog down the workbook. There is potential that the import data could grow as large as 10k+ rows, and I'm only at about half that currently and running into this problem. Outside of that, I'm not sure what else there is to try.
The QUERY function can help here and there are some great resources online.
=importrange(spreadsheet_url, range_string)
a typical example is:
=importrange("https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxx","Sheet1!A:Z")
You can wrap a QUERY function around this to manipulate your data.
QUERY is like a version of SQL and very powerful. It's in the format:
=QUERY({},"",1)
Your data range importrange("https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxx","Sheet1!A:Z") would go within {}.
Then within the "" part of the query, you could write your parameters for manipulating the data.
Example:
select Col1,Col4,Col5 where Col1 is not null and Col6 contains 'hello' order by Col1,Col7 desc label Col1 'new name 1',Col4 'new name 4'
The select bit allows you to specify specific columns from your importrange. If you want the all, then you could use select *.
The where item is where you build up your criteria using various or or and parameters.
is not null is another way of saying you want rows that have data.
contains is useful. You can also have matches, starts with, ends with and like. like can use wildcards %, so where Col1 like '%the%' would find 'hello there'.
order by is ascending unless you add desc, ie. order by Col1,Col2,Col4,Col5 desc,Col3.
label allows you to rename the columns, so let's say input column 1 is called 'Name1' and input column 2 is 'Name2' and you want them to be 'First name' and 'Surname, you would use label Col1 'First name', Col2 'Surname'.
If you like QUERY there are other powerful clauses, and they run in this order within the QUERY(range,"clauses",0):
select
where
group by
pivot
order by
limit
offset
label
format
options
One small point which you may come across, when you use importrange to get your data you need to reference the columns as Col1,Col2,Col3 within the QUERY.
If, however, your range is already in the same sheet (same or different tab), then you would reference column letters instead, eg. select A,B,C where A is not null order by A desc.
To make it more consistent and use the Col1,Col2,Col3 notation, you would put your internal range in an array {}.
QUERY(Sheet1!B:F,"select B,C,D where F is not null order by B,C",0)
would become:
QUERY({Sheet1!B:F},"select Col1,Col2,Col3 where Col5 is not null order by Col1,Col2",0)
{Sheet1!B:F} is smart because you can add columns in front of this range without needing to change your clause. So adding one column in front of Sheet1, would result in:
QUERY({Sheet1!C:G},"select Col1,Col2,Col3 where Col5 is not null order by Col1,Col2",0)
The other method would need you to alter your clause from:
QUERY(Sheet1!B:F,"select B,C,D where F is not null order by B,C",0)
to:
QUERY(Sheet1!C:G,"select C,D,E where G is not null order by C,D",0)
It's a lot to take in, but definitely worth persuing!

Pivoting programatically and carrying color information in summary of Google sheets

We have a base table that looks like this, in our main sheet called "MainData".
We would like to summarize it in a new worksheet. The summary needs to be by time, in a program management mode, where the "When" becomes the main view, in the following way. We could technically get a version of the top part of the table via Pivot, but that forces a new worksheet. We would like this entire view to be in our own second sheet of choice which we can call "Summary".
Not sure where to begin with this. The GETPIVOTDATA command seems a more convenient way to control how the pivot shows without forcing a worksheet, but it's the itemization of colours etc that is confusing. In each week's listing below that week column, we'd like to show the items but their cell needs to be coloured by the Status that item is in.
Not looking for ready made solutions (although I won't revolt if that's shared), just looking for pointers for which functions to look for. Thanks muchly!
Solution:
It's quite a task... :)
I have build working solution for you.
Go to this link to grab this (2 sheets - data and report)
Explanation:
Data sheet:
I added an extra column to source data - we will need this column in further query (you can hide this column)
={"Rep Desc";ArrayFormula(if(A2:A<>"";"Count of "&A2:A;))}
Report sheet:
I added 2 extra columns (A:B) (you can hide them later) to explain better what is going on. There are 4 main parts to this solution - you are able to pack all of them into one formula, but for sake of clarification I left them separate.
Part 1 Numbers of "Open / Closes / Attn"
This is simple query - we use extra column in data source to have desire description (Count of... instead just Attn, Closed, etc)
=QUERY({INDIRECT($A$1)};$B$1;1)
string to query
select Col5, count(Col4) where Col1 is not null group by Col5 pivot Col3 label Col5 ''
Part 2 - "Sum of Point"
Its Query again put into next query to remove headers + "Sum of Points" as an extra column (using inline array - {}):
={"Sum of Points"\QUERY(QUERY({INDIRECT($A$1)};B5;1);"select * offset 1";0)}
string to query
select sum(Col4) where Col1 is not null pivot Col3
Part 3 - "Features"
It is quite complicated... If I find more time I will describe what is going on here... but for now just code:
=QUERY(
transpose(ArrayFormula(SPLIT(
transpose(SPLIT(
TEXTJOIN("^";1;transpose(
{SPLIT(join(" ## ";transpose(query(transpose(QUERY({INDIRECT($A$1)};$B$9;1));"select Col1 offset 1";0)));" #";0;1);
QUERY(ArrayFormula(IF(TRANSPOSE(query(transpose(QUERY({INDIRECT($A$1)};$B$9;1));"select * offset 1";0))<>"";
query(QUERY({INDIRECT($A$1)};$B$9;1);"select Col1";0);""));"select * offset 1";0)}
))
;"# ";0;1))
;"^")))
;
"select * offset 1";0)
Part 4 - Conditional formatting
For range D9:H apply 3 rules with corresponding color :
=INDEX(INDIRECT("data!$A:$A");MATCH(D9;INDIRECT("data!$B:$B");0);1)="Open"
=INDEX(INDIRECT("data!$A:$A");MATCH(D9;INDIRECT("data!$B:$B");0);1)="Closed"
=INDEX(INDIRECT("data!$A:$A");MATCH(D9;INDIRECT("data!$B:$B");0);1)="Attn"
OK?
Is that what you were going to achieve?
Again - this is working copy for you:
Go to this link to grab this (2 sheets - data and report)

Resources