Filter order data to rows - google-sheets

I need to make sheet that will contain each order code, address, quantity and dates in one row for each order code.
I have sheet "Data" with orders (Address ID, Product code, quantity and Order ID) and i need to put it in other sheet "Export" in specific order. Is there a way to do it with functions or script?
I made test spreadsheet so everyone can see preview of what i need: test sheet
For example i have Address ID A001, i need to get each code and quantity from this address ID and put in row, in test spreadsheet i made example.
Sorry if I am asking too much, but i need some help or advice :)
Made picture so it would be easier to understand:
picture

The operation you need is called "unpivot" and has a couple of possible solutions, some of them purely functional and some utilizing Google Apps Script. Search for "unpivot" to explore them. Here goes one of possible functional solutions. It is simplified compared to your precise needs because I am not sure which of your headers ("dimensions") are unique. I'm assuming here that only the product code and address id are unique, because it looks like this in the data.
Make a new worksheet and put the formula below in A1:
=arrayformula(
split(
transpose(
split(
concatenate(
arrayformula(Data!$A$5:$A & "|" &Data!$C$3:$G$3 & "\"
)
);
"\")
);
"|")
)
Then put another formula in C1:
=arrayformula(
vlookup(A1:A; Data!$A$5:$G; match(B1:B; Data!$C$3:$G$3; 0)+2; 0)
)
This will give you the rudimentary idea of how to construct first the list of all possible combinations of dimension values (Code, Address ID in this case) and then fill in possible dependent values using VLOOKUP. Then you can use more VLOOKUPS to add more columns as needed.

Related

Is there a way to create a dynamic Query on Google Sheets?

I'm creating a database on Google Sheets for work and while I'm aware it's not the best solution, due to a number of restraints, that's what I've got to work with atm.
The thing is, I'm creating this for people who don't really know how to work with formulas on Google Sheets so I'm trying to be as user friendly as I can.
I'll use this sample sheet to try and demonstrate what I'm trying to do:
https://docs.google.com/spreadsheets/d/1tXM0IlswQVdwFum9a0pR5NsbtL5Uq_AH1tPbytXGvVg/edit#gid=0
One of the sheets is the Database, which will countain multiple columns of data (there's 10 on the sample, but the actual database is much larger).
There is another sheet called Column Index where I have a list of all columns, what kind of data they represent and a checkbox for people to select what data they want.
Finally, theres a third sheet called Data Extraction and I want to get the checked columns from the Database and send them to this sheet so people can download or copy this data to other worksheet.
It looks like a QUERY situation to me, but I'm not sure if it's possible to do it dynamically
This should do it:
=ArrayFormula(QUERY(
Database!A:K,
"select A,"&
TEXTJOIN(
",",
1,
IFNA(
REGEXEXTRACT(
ADDRESS(
1,
MATCH(
IF(
'Column Index'!C2:C,
'Column Index'!B2:B,
""
),
Database!1:1,
0
)
),
"[A-Z]+"
)
)
)
))
I built the query string, selecting the column indices that we wanted. No need for the "Col Index" Column.
Using Address, we can generate the appropriate column letter using a column address, then we just extract the letters part with a regex.
What I got was not that different as I also tried to construct the query string. The downside is it may be a bit buggy (but it works)
Here it is:
=query(Database!A1:K15,"select A,"&join(",",ArrayFormula(SUBSTITUTE(ADDRESS(1,filter(row('Column Index'!C2:C11),'Column Index'!C2:C11),4), "1", ""))))

Indirect formula referencing of formula in Google sheets

I have a a Google sheet which have multiple tabs in them
I use formula to get the consolidated info from the known names of the tabs as shown below
=UNIQUE({Appliances!A2:B;'Base, Trim & Crown'!A2:B;'Bathroom Accessories'!A2:B;'Bathroom plumbing'!A2:B;Cabinetry!A2:B;Carpet!A2:B;Closets!A2:B;'Entry Door'!A2:B;'Exterior and Interior Stone'!A2:B;'Exterior Lighting and Fans'!A2:B;'Exterior Siding'!A2:B;Fireplaces!A2:B;'Garage Doors'!A2:B;Gutter!A2:B;'Interior Door'!A2:B;'Kitchen Plumbing'!A2:B;'Paint Color'!A2:B;'Patio Stone'!A2:B;Roofing!A2:B;Slab!A2:B;Staircase!A2:B;Tile!A2:B;'Timbers, Beams & Ceilings'!A2:B;'Windows & Multislides'!A2:B;'Wood Flooring'!A2:B})
Suppose if I add a new sheet tab, this formula need to be updated again, which is cumbersome for me. So I am thinking is it possible to have a range in MASTER sheet that lists all sheetnames one below the other A2:A6 and synamically generate the sheet formula using indirect referencing?
So if I just add the new tab sheet name in MASTER the formula results are auto updated.
A2:A32 contains the list of sheetnames
=INDIRECT(CONCATENATE("{",TEXTJOIN(";",true,ARRAYFORMULA("'" &A2:A32 &"'!" & "A2:B")),"}"))
Well, first of all, INDIRECT doesn't work with ArrayFormula, sadly (I wish). But secondly, what's so cumbersome about updating the formula you have? Just format it like this:
=UNIQUE({
Appliances!A2:B;
'Base, Trim & Crown'!A2:B;
'Bathroom Accessories'!A2:B;
'Bathroom plumbing'!A2:B;
Cabinetry!A2:B;
Carpet!A2:B;
Closets!A2:B;
'Entry Door'!A2:B;
'Exterior and Interior Stone'!A2:B;
'Exterior Lighting and Fans'!A2:B;
'Exterior Siding'!A2:B;Fireplaces!A2:B;
'Garage Doors'!A2:B;
Gutter!A2:B;'Interior Door'!A2:B;
'Kitchen Plumbing'!A2:B;
'Paint Color'!A2:B;
'Patio Stone'!A2:B;
Roofing!A2:B;
Slab!A2:B;
Staircase!A2:B;
Tile!A2:B;
'Timbers, Beams & Ceilings'!A2:B;
'Windows & Multislides'!A2:B;
'Wood Flooring'!A2:B
})
Just add it where you want on the above list, leaving out the semicolon on the last item. (I'm not sure if you meant double quotes or not, so I left it as is.)
Or, if you really want to generate the sheet names from a list, you can use this, based on your above formula:
=ArrayFormula(TEXTJOIN(
";"&CHAR(10),
1,
"'"&SORT(FILTER(A:A,LEN(A:A)))&"'!A2:B"
))
which sorts in alphabetical order too. This outputs something you can copy+paste into your first formula.

Extract values from a range with 2 columns only if the value in column 1 contains a specific word in the column 2

I need to extract each individual person from a list that doesn't contain a certain activity (Project). Sounds easy but I can't quite get to the end of it.
Please check the example here on Sheet 2:
https://docs.google.com/spreadsheets/d/1qjbjXFCYj1qXrVVGNnhOj11asxT_o1xHWXerRqAl1UQ/edit#gid=2105763617
Here's the logic.
First I attempted to see if the individual only occurs once and if the Activity is not "Project"
=IF(A2<>"",IF(and(COUNTIF(A:A,A2)=1,B2<>"Project"),0,1),"")
Then I just extract the name that satisfies this criteria:
=query(ARRAYFORMULA(iF(I2:I=0,A2:A,"")), "where Col1 <>'' ")
This works, except there might be multiple assignments for the same person that does not contain the activity "Project" which my formula doesn't account for nor is it a simple dynamic arrayformula.
=UNIQUE(FILTER(A2:A, B2:B<>"Project"))
=UNIQUE(QUERY(A2:B, "select A where B <>'Project'", 0))
=UNIQUE(FILTER(A2:A, B2:B<>"Project",
NOT(REGEXMATCH(A2:A, "^"&TEXTJOIN("$|^", 1, FILTER(A:A, B:B="Project"))&"$"))))
While #player0's answer solves the question, it took a big performance hit on a sheet with >1000 rows.
Instead, I extracted all names that contained "Project" and then all names that did not contain "Project", then subtracted all the names from the first array to eliminate names that were in both.
=UNIQUE(FILTER(UNIQUE(FILTER(A2:A, B2:B<>"Project")), ISNA(MATCH(UNIQUE(FILTER(A2:A, B2:B<>"Project")), UNIQUE(FILTER(A2:A, B2:B="Project")),0))))
You may try this also:
{=IFERROR(INDEX($A$2:A$25,MATCH(0,IF($C$1<>$B$2:$B$25,COUNTIF($F$1:$F1,$A$2:$A$25), ""), 0)),"")}
N.B.
Cell C1 has criteria Project, using cell reference makes the formula
dynamic rather than hard coded.
Enter this formula in cell F2, finish with Ctrl+Shift+Enter,
and fill down.

Google Sheets formula that returns all values for which multiple criteria in other columns apply

My problem, generally stated:
I need a formula that returns all the values in a specific column for which multiple criteria in other columns of the respective row apply.
My problem, specifically stated:
I would like a formula that returns all the values in Column A for which Column C is "John", Column E is "Apples", Column G is "Earth" and both Columns H and I are empty. See here for a simplified illustration of my problem with dummy data. The correct formula, dragged down, would output a list with the values "1", "4", and "14". If you'd like to try out some stuff in the linked spreadsheet, feel free to do so in a copy of the original sheet so others can see my original data/formulas.
What I've tried so far:
Simply filtering was not an option because the data is on a separate sheet within the same spreadsheet. I also knew VLOOKUP and INDEX/MATCH were not going to do what I wanted - VLOOKUP doesn't handle multiple criteria, and while the MATCH part of INDEX/MATCH can be turned into an array to specify multiple criteria, it only returns the first value for which all conditions are true, while I need all of them.
I then tried the following formula (Formula 1 in the linked spreadsheet):
=IFERROR(INDEX($A$2:$I, SMALL(IF(COUNTIF($K$2, $C$2:$C)*COUNTIF($K$3, $E$2:$E)*COUNTIF($K$4, $G$2:$G), ROW($A$2:$I)-MIN(ROW($A$2:$I))+1), ROW(A1)), COLUMN(A1)),"")
It worked like a charm, until I wanted to include the condition that both columns H and I should be empty. I tried this, but for some reason I don't understand it didn't work (Formula 2 in the linked spreadsheet):
=IFERROR(INDEX($A$2:$I, SMALL(IF(COUNTIF($K$2, $C$2:$C)*COUNTIF($K$3, $E$2:$E)*COUNTIF($K$4, $G$2:$G)*COUNTIF($K$5, $H$2:$H)*COUNTIF($K$6, $I$2:$I), ROW($A$2:$I)-MIN(ROW($A$2:$I))+1), ROW(A1)), COLUMN(A1)),"")
Then I tried to nest my first formula into an IF/VLOOKUP (Formula 3 in the linked spreadsheet):
=IFERROR(IF(VLOOKUP(INDEX($A$2:$I, SMALL(IF(COUNTIF($K$2, $C$2:$C)*COUNTIF($K$3, $E$2:$E)*COUNTIF($K$4, $G$2:$G), ROW($A$2:$I)-MIN(ROW($A$2:$I))+1), ROW(A1)), COLUMN(A1)),$A$2:I,8,FALSE)<>"","",INDEX($A$2:$I, SMALL(IF(COUNTIF($K$2, $C$2:$C)*COUNTIF($K$3, $E$2:$E)*COUNTIF($K$4, $G$2:$G), ROW($A$2:$I)-MIN(ROW($A$2:$I))+1), ROW(A1)), COLUMN(A1))),"")
This worked if I only asked for column H to be empty, but a) it is very unwieldy, b) it gives you blanks in the list it returns, which I do not want, and c) I could not get it to work for the condition that both columns H and I need to be empty using OR.
That's where I'm stuck, and I haven't come up with a good solution. Knowing this forum, I'm sure someone has an elegant solution I was not smart enough to find :)
I'm on phone so formating will suffer.
Create a new column on the left and insert the following into cell A2
=if(D2="John", if(F2="Apples", if(H2="Earth", if(I2="", if(J2="", B2,""), "" ), "" ), "" ), "")

How can I filter my search in a column on google sheet which collects data from a form?

I would like to perform a multi criteria search of data in a column- contains data of check boxes(more than one option chosen).
For a clearer picture of what I am trying to do, screenshot below is a question in a form
Data from the form are saved in sheets like below,
So my concern here is if I would like to search/filter for the rows that contain "Commercial", the rows with Commercial,Engineering doesn't show up. That's definitely not an effective search.
Any advise on how can I go about this issue is kindly appreciated. If
Let's say you have your form in the response sheet in columns A to P, with the multiple choice in col D. If you want to filter your data on the word 'Commercial' you can either do:
=filter(A2:P, regexmatch(A2:P, "Commercial"))
or use query():
=query(A2:P, "select * where B contains 'Commercial' ")
Note: depending on your locale you may have to change the commas to semi-colons in order for the formulas to work.
I hope that helps ?
Following JPV's answer, I developed a line to make the query useful if you want to cross two categories. Let's suppose that someone in your checkbox example had picked all the options (IT, HR, Commercial, Engineering); and that you have created the cell with the dropdown option box in cell B1 with all your options, as JPV said.
Then, you want to filter and see all the people who had chosen IT and Commercial. You would, for that, create a second cell with the dropdown option box in, lets say C1; and then your query would be:
=query(A2:P, "select * where B contains '"&B1&"' and B contains '"&C1&"' ")
=FILTER(MOBILE!A2:E2000, ISNUMBER(SEARCH(A1,MOBILE!A2:A2000)))
SEARCH function will return a number of the position of the searched word (A1) in the searched strings in range (MOBILE!A2:A2000).
If the result of search is a number (ISNUMBER), then filter will return the TRUE rows result from the range MOBILE!A2:E2000.

Resources