Splitting data separated by a | in a cell to new rows - google-sheets

I have a Spreadsheet (see link at the bottom of the page) that has 1 row and 3 columns.
I want to take the data contained and split it out, resulting in a row by row breakdown.
Is anyone aware of how this could be done using a formula? It would save me a bunch of time doing it manually!
DemoSheet - This shows what the input and the desired outputs are
EDIT:
The Input sheet shows the data as I have it, using metasyntactic variables as examples (real data will vary, but will always follow the same formatting).
For every email address in the email column, I need to do the following
Get the list of managers and members and have it output as per the Desired Output 1 sheet. So for each entry in ColA, a row entry for each of the data in B and C, as if they were concatenated, split by " | " and transposed vertically.
Repeat the above process but only for managers (as per the the Desired Output 2 sheet).

Is this what you need?
Output1:
=arrayformula({"Email","Members";
query(
array_constrain(
{
flatten(split(rept("|"&Input!A2:A,len(regexreplace(Input!B2:B&" | "&Input!C2:C,"[^\|]",))+1),"|")),
trim(flatten(split(Input!B2:B&"|"&Input!C2:C,"|")))
},
max(if(Input!B2:B<>"",len(regexreplace(Input!B2:B&" | "&Input!C2:C,"[^\|]",))+1,))*counta(Input!B2:B),2),
"where Col1 is not null",0)
})
Output2:
=arrayformula({"Email","Manager";
query(
array_constrain(
{
flatten(split(rept("|"&Input!A2:A,len(regexreplace(Input!B2:B,"[^\|]",))+1),"|")),
trim(flatten(split(Input!B2:B,"|")))
},
max(if(Input!B2:B<>"",len(regexreplace(Input!B2:B,"[^\|]",))+1,))*counta(Input!B2:B),2),
"where Col1 is not null",0)
})
You could optionally wrap unique() within the arrayformula if it is likely that you'll get duplicates in the dataset.

Related

Google Sheets Query Search Box | Search criteria

so basically I have a searchbox in my sheet that searches and pulls up data. For a reference see this image: https://i.imgur.com/MVTUCSw.png. So basically in cell A4 I put the data that I am looking for, but my formula restricts me to only looking up stuff in 1 row. For example, data starting with the word MELD, but I would like to be able to also look up data based on for example the someone their name.
The formula I use for the searchbox: =QUERY({'Pallets & Locaties'!A2:G;Voorraadverschillen!A2:G}, "SELECT * WHERE Col1 "&Opzoeken!B4&" '"&A4&"'")
The data that I want to be able to look up is stored in 2 sheets: Pallets & Locaties - https://i.imgur.com/qV7h2tz.png and in Voorraadverschillen - https://i.imgur.com/foqLkKa.png.
The searchbox is only able to lookup data in row, but I just want to be able to search for any kind of stored data in any of the sheets.
Here is my sheet for reference: https://docs.google.com/spreadsheets/d/10wmnxV16JUiD_b_54abkiLPwTqLITWRcUw3gsqvXoBE/edit?usp=sharing
I'd recommend you add more rows for the lookup criteria and add a column for what column it would search for.
Sheet modification:
Formula:
=QUERY({'Pallets & Locaties'!A2:G;Voorraadverschillen!A2:G}, "SELECT * WHERE "&TEXTJOIN(" AND ", TRUE, ARRAYFORMULA(IF(ISBLANK(A4:A10), "", A4:A10&" "&B4:B10&" '"&C4:C10&"'"))))
Test Sheet
Note:
The above formula will allow you to search on other columns with their own words and criteria to search.
Only rows with Kolom values will be included in the criteria. If you only need Col1 criteria, make sure to leave other rows blank.
This does use an AND search, meaning all of the criteria should be true and match the row. Feel free to use OR in the TEXTJOIN function if you only want to search all rows matching any of the criteria.
This will only search on sheets Pallets & Locaties and Voorraadverschillen. Add the necessary sheets if you need them.
EDIT:
Cleaned up the formula to not be so repetitive.
=IF(A4<>"",(QUERY({'Pallets & Locaties'!A2:G;Voorraadverschillen!A2:G},"Select * WHERE "&textjoin(" OR ", true, arrayformula("Col"&ROW(1:7)&" "&B4&" '"&A4&"'")))),(QUERY({'Pallets & Locaties'!A2:G;Voorraadverschillen!A2:G},"Select * WHERE Col1 IS NOT NULL")))
This searches every column for the data, as long as data is not identical in two columns you won't have issues. An example would be the search criteria "MELD" being in both Column A and B. If that were the case, only the results from the first matching column would populate.

Generating rows and columns w.r.t available data using formula

I have an input like below in Google Sheet:
I need to generate rows and columns with the above available data given below:
Conditions and tried formula:
WORKED - To reverse and transpose column 'Items' from input to generated column 'Item Order' in output. Below formula is used for that and worked.
=
Filter(
{
TRIM(FILTER(TRANSPOSE(C2:F2),TRANSPOSE(C2:F2)<>""));
QUERY(SORT(TRANSPOSE(C3:F3),SEQUENCE(COLUMNS(C3:F3)),),"where Col1 is not null",0)
},
{
FILTER(TRANSPOSE(C2:F2),TRANSPOSE(C2:F2)<>"");
QUERY(SORT(TRANSPOSE(C3:F3),SEQUENCE(COLUMNS(C3:F3)),),"where Col1 is not null",0)
}<>"
")
I need to generate column 'Side' and 'Row' in output for respective items from input. Here, the last item in front side needs to be assigned 'Right End' and the first item in back side needs to be assigned 'Left End'. I'm not sure how to include this logic for generating these columns to above formula.
Try
={arrayformula(split({flatten(OFFSET(C2,,,,COUNTA(C2:G2)-1)&"|"&B2&"|"&A2);OFFSET(C2,,COUNTA(C2:G2)-1)&"|right end|"&A2},"|"));
query(sort(arrayformula(split({column(C3)&"|"&C3&"|left end|"&A3;
flatten(column(OFFSET(C3,,1,,COUNTA(C3:G3)-1))&"|"&OFFSET(C3,,1,,COUNTA(C3:G3)-1)&"|"&B3&"|"&A3)},"|")),1,false),"select Col2,Col3,Col4")}

Why my ArrayFormula is giving error? How do I correct it? (I'm not looking for another Arrayformula as solutions!)

I wanted a ArrayFormula at C1 which gives the required result as shown.
Entry sheet:
(Column C is my required column)
Date Entered is the date when the Name is Assigned a group i.e. a, b, c, d, e, f
Criteria:
The value of count is purely on basis of Date Entered (if john is assigned a on lowest date(10-Jun) then count value is 1, if rose is assigned a on 2nd lowest date(17-Jun) then count value is 2).
The value of count does not change even when the data is sorted in any manner because Date Entered column values is always permanent & does not change.
New entry date could be any date not necessarily highest date (If a new entry with name Rydu is assigned a on 9-Jun then the it's count value will become 1, then john's (10-Jun) will become 2 and so on)
Example:
After I sort the data in any random order say like this:
Random ordered sheet:
(Count value remains permanent)
And when I do New entries in between (Row 4th & 14th) and after last row (Row 17th):
Random Ordered sheet:
(Doesn't matter where I do)
I already got a ArrayFormula which gives the required result:
={"AF Formula1"; ArrayFormula(IF(B2:B="", "", COUNTIFS(B$2:B, "="&B2:B, D$2:D, <"&D2:D)+1))}
I'm not looking for another Arrayformula as solutions. What I want is to know what is wrong in my ArrayFormula? and how do I correct it?
I tried to figure my own ArrayFormula but it's not working:
I got Formula for each cell:
=RANK($D2,FILTER($D$2:$D, $B$2:$B=$B2),1)
I figured out Filter doesn't work with ArrayFormula so I had to take a different approach.
I took help from my previous question answer (Arrayformula at H3) which was similar since in both cases each cell FILTER formula returns more than 1 value. (It was actually answered by player0)
Using the same technique I came up with this Formula which works absolutely fine :
=RANK($D2, ARRAYFORMULA(TRANSPOSE(SPLIT(VLOOKUP($B2, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ","))), 1)
Now when I tried converting it to ArrayFormula:
($D2 to $D2:$D & $B2 to $B2:$B)
=ARRAYFORMULA(RANK($D2:$D,TRANSPOSE(SPLIT(VLOOKUP($B2:$B, SUBSTITUTE(TRIM(SPLIT(FLATTEN(QUERY(QUERY({$B:$B&"×", $D:$D}, "SELECT MAX(Col2) WHERE Col2 IS NOT NULL GROUP BY Col2 PIVOT Col1", 1),, 9^9)), "×")), " ", ","), 2, 0), ",")), 1))
It gives me an error "Did not find value '' in VLOOKUP evaluation", I figured out that the problem is only in VLOOKUP when I change $B2 to $B2:$B.
I'm sure VLOOKUP works with ArrayFormula, I fail to understand where my formula is going wrong! Please help me correct my ArrayFormula.
Here is the editable sheet link
if I understand correctly, you are trying to "rank" B column based on D column dates in such way that dates are in theoretical ascending order so if you randomize your dataset, the "rank" of each entry would stay same and not change based on the randomness you introduce.
therefore the correct formula would be:
={"fx"; INDEX(IFNA(VLOOKUP(B2:B&D2:D,
{INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1),
IFERROR(1/(1/COUNTIFS(
INDEX(SORT(B2:D, 3, 1),,1),
INDEX(SORT(B2:D, 3, 1),,1), ROW(B2:B), "<="&ROW(B2:B))))}, 2, 0)))}
{"fx"; ...} array of 2 tables (header & actual table) under each other eg. ;
outer shorter INDEX or longer ARRAYFORMULA (doesnt matter which one) is needed coz we are processing an array
IFNA for removing possible #N/A errors from VLOOKUP function when VLOOKUP fails to find a match
we VLOOKUP joint B and D column B2:B&D2:D in our virtual table {} and returning second 2 column if there is an exact match 0
our virtual table {INDEX(SORT({B2:B&D2:D, D2:D}, 2, 1),,1), ...} we VLOOKUP from is constructed with 2 columns next to each other eg. ,
we are getting the first column by creating an array of 2 columns {B2:B&D2:D, D2:D} next to each other where we SORT this array by date/2nd column 2, in ascending order 1 but all we need after sorting is the 1st column so we use INDEX where we bring all rows ,, and the first column 1
now lets take a look on how we getting the 2nd column of our virtual table by using COUNTIFS which will mimic the "rank"
IFERROR(1/(1/ is used to remove all zero values from the output (all empty rows would have 0 in it as the "rank")
under COUNTIFS we put 2 pairs of arguments: "if column is qual to column" and "if row is larger or equal to next row increment it by 1" ROW(B2:B), "<="&ROW(B2:B))
for "if column is qual to column" we do this twice and use range B2:D and sort it by date/3rd column 3 in ascending order 1 and of this we again need only the 1st column so we INDEX it and return all rows ,, and first column 1
with this formula you can add, remove or randomize your dataset and you will always get the right value for each of your rows
as for why your formula doesnt work... to not get #N/A error for vlookup you would need to define the end row of the range but still, the result wont be as you would expect coz formula is not the right one for this job.
as mentioned there are functions that are not supported under AF like SUM,AND,OR and then there are also functions which work but in a different way like IFS or with some limitations like SPLIT,GOOGLEFINANCE,etc.
I have answered you on the tab in your shared sheet called My Practice thusly:
You cannot split a two column array as you have attempted to do in cell CI2. That is why your formula does not work. You can only split a ONE column array.
I understand you are trying to learn, but attempting to use complicated formulas like that is going to make it harder I'm afraid.

Merging data in google sheets from multiple sheets with varying number of rows

I have multiple google sheets with each containing variable number of rows but fixed set of columns. The number of rows can change in any sheet with time. How can i create summary sheet with data from all sheets placed one after the other? eg. If sheet 1 has 5 rows and sheet 2 has 6, i want the summary sheet to have 11 rows with 1-5 containing data from sheet 1 and 6-11 data from sheet 2.
= {
FILTER(NamedRange1, NamedRange1Col1 <> '');
Filter(NamedRange2, NamedRange1Col1 <> '')
}
Please create a named range for each sheet. This ranges will comntain your data.
Within each named range, also create a named range column. This can be the first column of every named range, or any column.
We are using the filter function FILTER so that you do not import empty rows. You dont have to use it though. The curly braces are semicolon are the crucial parts. In general, you "stack" multiple arrays as follows:
= {Array1; Array2;...;Array n}
the correct syntax is:
={FILTER(Sheet1!A:C; Sheet1!B:B<>"");
FILTER(Sheet2!A:C; Sheet2!B:B<>"")}
and another solution would be:
=QUERY({Sheet1!A:C; Sheet2!A:C}; "where Col2 is not null", 0)

Data reduction via IMPORTRANGE

I am trying to do some data reduction in my Google Sheets by using the following IMPORTRANGE formula:
=query(importrange("https://docs.google.com/a/ap.averydennison.com/spreadsheets/d/1xz1lXY-w5Ii_aWqVAhHgRCmeoes9ltSUtibE4kzhMHA/edit#gid=2051232966","SF_Flex_Rel!a:l"),
"select * where Col1 = '"&text(B1,"###")&"'",1)
The 'source' sheet has a whole lot of sales data records. What I am trying to do in the new sheet via this formula is only bring in the sales records from the source sheet that match the customer number specified in cell B1.
It seems to work OK if I limit the IMPORTRANGE to only query about 10,000 rows. Once I go over around 20,000 rows the screen will briefly flash up the records, then a small progress bar shows in the top right corner of the sheet and the records disappear. The cell with the formula just shows #ERROR! with no other comments to tell me why.
Is there something wrong with my formula syntax?
Is there a better way to achieve this data reduction?
Is there some undocumented data limitation on IMPORTRANGE function (I am using 'new' Google Sheets)?
try like my example :
=QUERY( // data
IMPORTRANGE(
"Spreadsheet Key", // spreadsheet key
"DATA!A:C" // datarange
),
"SELECT Col1 WHERE Col2=" & "'" & B2 & "'" // query
)
I had the same problem. This answer helped me find a workaround : https://productforums.google.com/forum/#!topic/docs/RxVUFGWQ2Y4
In my example :
1) In the spreadsheet where the data is I have added a few empty columns (E to H) in order to display 4 columns of data in 5 maximum rows.
=Query(Sheet1!A:D,"select * Where A contains 'KEYWORD' limit 5",1)
2) Then in the other spreadsheet:
=ImportRange("https://docs.google.com/spreadsheets/d/ss_key_here/", "'Sheet1'!E1:H5")

Resources