I'm wanting to loop through a list of values in a column (ie: Value1|Value2|Value3), use those to VLOOKUP a column, then return the concatenated values into the cell.
Sheet example: BUSINESSES.csv
ID
Business Name
Services
Tags
(Expected Outcome)
6259
22Handy
Business
Test1|Test2
6260
AAFMAA Wealth
Business|Financial Management
Test1|Test2|Finances|Accounting|Budgeting
Notice the "TAGS" column is empty. This is where I want to return results (and enter the formula).
The goal is to take each "Service" and look through the following separate sheet example:
Example: SERVICES.csv
Service Name
Tags to add
Financial Management
Finances|Accounting|Budgeting
Business
Test|Test2
So if a Business has a service of "Business" then it should return "Test1|Test2"
If a business has the services "Business|Financial Management" then it should return "Test1|Test2|Finances|Accounting|Budgeting" because it is pulling tags from both of the services the business is assigned to.
I've tried different combinations of INDEX, VLOOKUP, FILTER, and REGEXMATCH but to no avail.
Something like: =INDEX( FILTER( Services!A2:A, IF( REGEXMATCH( Services!A2:A, C2,))))......
try:
=ARRAYFORMULA(SUBSTITUTE(SUBSTITUTE(TRIM(FLATTEN(QUERY(TRANSPOSE(IFNA(VLOOKUP(
IF(IFERROR(SPLIT(C2:C, "|"))="",, SPLIT(C2:C, "|")),
{G:G, SUBSTITUTE(H:H, " ", "×")}, 2, 0))),,9^9))), " ", "|"), "×", " "))
Related
I have put together some sample data in a sheet here.
Essentially I have a column with names separated by a pipe (col B in example). I have a separate table (col F:G) that maps each name to a role type. I want to add a column that looks up each individual person in the pipe delimited string and returns a similarly structured string containing their job roles.
I can do this on a row by row basis (see col C), but this is a table that will grow (and is sourced from elsewhere) so ideally I'd like to use an array formula that will work for every row. However, because of the SPLIT() in there I can't get this to work.
Is there a way I can achieve this?
try:
=ARRAYFORMULA(REGEXREPLACE(REGEXREPLACE(TRIM(FLATTEN(QUERY(TRANSPOSE(
IFERROR(VLOOKUP(SPLIT(B2:B, "|"), {F:F, G:G&"|"}, 2, 0))),,9^9))),
"\|$", ), "\| ", "|"))
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.
I have a sheet that looks like this. You'll notice the columns contain different social media links.
I would like for the sheet to look like this - with columns containing similar social media links.
Is there a way to automate this categorization? Here's the sheet if helpful, thanks.
If you can replace the cell values of Link 1 and Link 2 with the website name that you want in that column then you can use FILTER to get values that match your criteria.
If your data looks like this:
Then you can use the following formula in F3 provided you've labelled the headings appropriately (facebook, instagram etc)
=ArrayFormula(FILTER(TRANSPOSE(SPLIT(TEXTJOIN(" ", 1, $B$3:$C), " ")), SEARCH(F$2, TRANSPOSE(SPLIT(TEXTJOIN(" ", 1, $B$3:$C), " "))), SEARCH($E3, TRANSPOSE(SPLIT(TEXTJOIN(" ", 1, $B$3:$C), " ")))))
Don't know if this helps, but here's an option with a formula in one cell - E2. You can put this on another sheet if preferred:
=arrayformula(
{A2:C2;
query(
{
vlookup({sequence(counta(A3:A),1,1,2),sequence(counta(A3:A),1,1,2),sequence(counta(A3:A),2)},{sequence(counta(A3:A)*2),query({row(A3:A),A3:A,B3:B;row(A3:A),A3:A,C3:C},"where Col2 is not null order by Col2,Col3",0)},{2,3,4,4},0)
},"select Col2,Col3,Col4 order by Col1",0)
})
If you have more Link columns than just two, I can provide different code.
I have an export from our student information system that has multiple rows for each student, depending on how many contact email addresses the parent entered.
Sample data from the export
I would like to combine all the contact addresses either into multiple columns on the same row or even all to the same cell would be fine. After many attempts through a lot of searching, I can get it to work with =join(char(10), filter(extract.csv!G:G,extract.csv!A:A=J2)) and manually filling the formula down. (Although I'd rather not have the return first but rather just between the results, but I can live with it if it's not possible.)
What'd I'd love is to have that in an arrayformula so that I don't have to copy it down but I can't figure out how to adjust the last reference to the J row. If I leave it as is, it puts the same values in every cell to match the J2 data.
with arrayformula
Or is there another way to get what I'm trying for? Thanks for any help... I'm just a teacher who loves to code and automate things muddling through and learning bits and pieces as I go!
It's probably worth posting this, because it's how far I got just creating some representative data of my own before I realised that you'd posted a sheet for us (thank you).
=ArrayFormula(if(mod(sequence(countunique(A2:A),D2,0),D2)<countif(A2:A,unique(filter(A2:A,A2:A<>""))),
vlookup(vlookup(unique(filter(A2:A,A2:A<>"")),{A2:A,row(A2:A)},2,false)+MOD(sequence(COUNTUNIQUE(A2:A),D2,0),D2),{row(A2:A),B2:B},2,false),))
D2 is a helper cell which contains the maximum number of contacts per student - either from formula or entered manually.
I will have a go with your data, but I wasn't quite clear whether the student's own email should come first, followed by the parent contacts? I'm kind of hoping that the secondary email isn't populated because it would complicate things further.
Here's how it looks with your data - same formula with slightly different columns:
=ArrayFormula(if(mod(sequence(countunique(A2:A),I2,0),I2)<countif(A2:A,unique(filter(A2:A,A2:A<>""))), vlookup(vlookup(unique(filter(A2:A,A2:A<>"")),{A2:A,row(A2:A)},2,false)+MOD(sequence(COUNTUNIQUE(A2:A),I2,0),I2),{row(A2:A),G2:G},2,false),))
where I2 is currently set to 5 - it can be worked out from
=max(countif(A2:A,unique(filter(A2:A,A2:A<>""))))
if you want to make it more dynamic.
The issue being that I can't think of an easy way to remove the blank email address for the first student at the moment (I'm a bit surprised that the download contains blank addresses - data quality?).
I have added a new sheet ("Erik Help"), which is a duplicate of your "AutoFillData" sheet. In my sheet, I cleared Column AD and then placed the following formula in AD1:
`=ArrayFormula({"Contact Emails";IF(J2:J="",,IFERROR(VLOOKUP(J2:J,{UNIQUE(FILTER(extract.csv!A2:A,extract.csv!A2:A<>"")),SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(ISERROR(VLOOKUP(UNIQUE(FILTER(extract.csv!A2:A,extract.csv!A2:A<>""))&""&TRANSPOSE(UNIQUE(FILTER("|"&{extract.csv!E2:E;extract.csv!F2:F;extract.csv!G2:G},{extract.csv!E2:E;extract.csv!F2:F;extract.csv!G2:G}<>"")))&"",extract.csv!A2:A&"|"&extract.csv!E2:E&"|"&extract.csv!F2:F&"|"&extract.csv!G2:G,1,FALSE)),,TRANSPOSE(UNIQUE(FILTER({extract.csv!E2:E;extract.csv!F2:F;extract.csv!G2:G},{extract.csv!E2:E;extract.csv!F2:F;extract.csv!G2:G}<>"")))))," ",COUNTA(UNIQUE(FILTER({extract.csv!E2:E;extract.csv!F2:F;extract.csv!G2:G},{extract.csv!E2:E;extract.csv!F2:F;extract.csv!G2:G}<>""))))))," ",CHAR(10))},2,FALSE)))})'
Explaining this formula fully would take quite a long time.
In general, what it does is form a virtual 2D grid (never seen by the user) with the unique list of student IDs running vertically at left and the unique list of all email addresses (with an appended delineator) running horizontally across the top. If the combination of student ID and that email address is found in any string formed by the mash-up of studentID|email1|email2|email3, then that email address fills the virtual grid; if not, then that cross-section of the grid is left null.
This leaves a grid where all possible emails are filled in horizontally somewhere across from each unique ID, rather than being on separate lines.
Finally, a quirk in the QUERY function is used to combine all non-null entries per row. That is, the QUERY function can have any number of headers, not just 0 or 1. By having QUERY request every email section of the grid as headers and then TRIMing out spaces, we wind up with all the emails for each student ID together.
Then it's just a matter of replacing the remaining spaces with a line return character, i.e., CHAR(10).
Here are a few solutions (in sheets kishkin 1 in kishkin 2 respectively).
Emails in one row in separate columns:
=ARRAYFORMULA(
IF(
J2:J = "",,
TRIM(
SPLIT(
VLOOKUP(
J2:J,
SPLIT(
TRANSPOSE(QUERY(
QUERY(
FILTER({extract.csv!A:A & "♥", extract.csv!G:G & "♦"}, extract.csv!A:A <> ""),
"SELECT MAX(Col2)
GROUP BY Col2
PIVOT Col1",
1
),, COUNTA(extract.csv!A:A)
)),
"♥"
),
2,
),
"♦"
)
)
)
)
Emails in a single cell:
={
"CONTACT EMAILS";
ARRAYFORMULA(
IF(
J2:J = "",,
REGEXREPLACE(
VLOOKUP(
J2:J,
SPLIT(
TRANSPOSE(QUERY(
QUERY(
FILTER({extract.csv!A:A & "♥", extract.csv!G:G & CHAR(10)}, extract.csv!A:A <> ""),
"SELECT MAX(Col2)
GROUP BY Col2
PIVOT Col1",
1
),, COUNTA(extract.csv!A:A)
)),
"♥"
),
2,
),
"(?m)^\s+|\s+$",
)
)
)
}
I'm trying to get a formula that pulls a value from a sheet based on a date to find all occurrences and join them together.
My original question is here for context.
This works really well, but if a user submits a new order at a later date for a date that already has a submission, I get the first and not any additional.
Here's my current code, which also checks for comma and space, and adds a carriage return.
=regexreplace(IFERROR(VLOOKUP(B1, IMPORTRANGE("source", "B2:C"), 2, 0)), ", ", char(10))
How can I combine multiple cell values based on criteria?
=ARRAYFORMULA(TEXTJOIN(CHAR(10),1,
REGEXREPLACE(IFERROR(QUERY(IMPORTRANGE(
"1JCOLm7ZQgR0qgtzq_98E4vDie7-FM-WlwiSZwgpB22k", "B2:C"),
"select Col2 where Col1=date'"&TEXT(B1,"yyyy-mm-dd")&"'")),
", ", CHAR(10))))