Query only most recent value if duplicates exist - google-sheets

I work at a warehouse and I am developing an Inventory System. When products come in, it is because they are damaged. I have one person fill out a row in Google Sheets when the product arrives (Sheet1 in the workbook link below). I mainly need Barcode, Issue, and Date from this Sheet).
Next, a mechanic fixes the product and fills out a google form with his name and the barcode of the product; the responses are Form Responses 1 in the workbook link below.
I then pull the data for all the incoming products from Sheet1 to a new tab (Barcodes In/Out in the workbook link below), querying Barcode, Issue, and Date. I pull the data for all the outgoing product in another column in this tab, querying the Barcode from the Form Responses 1. Column E (Backlog) has a formula that only shows barcodes of products that have not been repaired (gone "out").
I pull the data for what is in my Back log (products still in warehouse needing repair) into another tab named Back Log. This was working perfectly until I realized products can come back to our warehouse (i.e. "123" can come in and get fixed and sent out again. "123" can come back again for more repairs.)
This poses a problem because Back Log now shows "123" twice with two different Issues.
I need Back Log to query "123" only and only with the most recent Issue.
This is a lot of info, but I tried to be as detailed as I could. Thank you for your help in advance!
Here is the link to my workbook

In G2 I entered
=ArrayFormula(iferror(vlookup(unique(Sheet1!B2:B), sort({Sheet1!B2:B, Sheet1!A2:F}, 7, 0), {2, 3, 4, 5, 6}, 0)))
UPDATE: Based on new info...
=query(ArrayFormula(iferror(vlookup(unique(Sheet1!B2:B), sort(filter({Sheet1!B2:B, Sheet1!A2:F}, not(regexmatch(Sheet1!B2:B&"", textjoin("|", 1, filter('Barcodes In/Out'!D2:D, isna(match('Barcodes In/Out'!D2:D, 'Barcodes In/Out'!E2:E, 0))))))), 7, 0), {2, 3, 4, 5, 6}, 0))), "where Col1 <>''")
See if that works for you?

Related

How to create a searcher which looks for more than one value in a database?

it's nice to be here and join this forum.
I have an issue which I would like to solve.
I have a database, where I would like to input multiple locations, and then, to have displayed the IDs and region of multiple clients next to it.
Say, for example, that I have a sheet with the info of clients.
Searcher
ClientID
City
Region
Caracas
01
Berlin
Europe
Berlin
02
Monaco
Europe
03
Caracas
LatAm
I would like to copy and paste the names of my cities in the cells under the Searcher column and that only the cities displayed there are shown under the results.
In the above example, I would like my sheet to show both the info of Client #1 and Client #3.
The closest which I have made it to the solution of this problem can be seen in this spreadsheet.
Database Link
But sadly, it only works with one value. In the sheet I shared, I would like to have the info show the same fiels for both "Upper Marlboro" and "Darlington".
The sheet above can be edited to test this.
Resume:
Is there a way to solve this issue a create a multiple value searching machine in Google Sheets?
I have tried before with the FILTER and SEARCH formulas, like this:
=FILTER($P$3:$Z,SEARCH(B4,$Y$3:$Y))
And with Sheet Queries, like this:
=QUERY(CityDB,"SELECT * WHERE J = 'Fairfax'")
But sadly, it only has allowed me to search for just one value.
use:
=FILTER(H3:J, REGEXMATCH(I3:I, TEXTJOIN("|", 1, B4:B)))
or:
=QUERY(H3:J, "where I matches '"&TEXTJOIN("|", 1, B4:B)&"'", )

How to change the value of a cell only when everyone has left the house?

I have a sheet consisting of entries that look like this, which I use to keep track of when the members of my family are at home:
DateTime
User
In/Out
5/29 13:00
Mike
In
5/29 13:05
Fred
Out
The rows are added via automation from everyone's phone using IFTTT. I have some flexibility in the format, but not a lot.
I would like to create a cell that changes ONLY when everyone is out of the house. Another IFTTT rule will watch that cell, and when it changes it will start the roomba. So the cell should NOT change if anyone returns home, it should only change if everyone has left.
One way I can think to do this is to set the watched cell to the last timestamp when everyone has left the house. That way, it will only update to a new value when everyone has once again left. Anytime there's a new row, if the status of everyone is Out, it will update the last timestamp.
I'm having a little trouble composing the formulas to keep track of when everyone is Out. This involves looking back through the most recent entries and finding the last time everyone who isn't the current user was out. I figure I can use a filter and a reverse sort and a lookup for every row in the table, but this seems a little complicated and inefficient.
Is there a better way to accomplish what I want?
you could track it like:
=SORTN(SORT(B2:C, ROW(B2:B), 0), 9^9, 2, 1, 1)
and then:
=SUMPRODUCT(INDEX(SORTN(SORT(FILTER({B2:C,
ROW(B2:B)}, B2:B<>""), 3, 0), 9^9, 2, 1, 1)="Out",, 2))=
COUNTUNIQUE(B2:B)
where:
TRUE = everybody out
FALSE = someone in
to get a time when house is empty:
=IF(SUMPRODUCT(INDEX(SORTN(SORT(FILTER({B2:C,
ROW(B2:B)}, B2:B<>""), 3, 0), 9^9, 2, 1, 1)="Out",, 2))=COUNTUNIQUE(B2:B),
INDEX(SORTN(SORT(A2:C, ROW(B2:B), 0), 9^9, 2, 2, 1), 1, 1), "someone home")
I think I got it, many thanks to player0.
The columns in yellow are written by the IFTTT automation. Columns D and E are set to the status of Mike and Carrie, as of that time. D3 is set to:
=INDEX(TRANSPOSE(SORTN(SORT(A$2:C3, ROW(B$2:B3), 0), 9^9, 2, 2, 1)),3)
and filled down for the rest of column D, which also populates E.
Once you have a row with a timestamp and everyone's status, it's a relatively simple thing to pick out the latest row where everyone is out. Cell G4 is set to:
=INDEX(SORT(FILTER(A2:E,D2:D="OUT",E2:E="OUT"),1,FALSE),1,1)
In this example, it shows that the last time everyone was out was on 6/5, which is correct. As more rows are added, the value does not change again until the next time everyone is out, which is important for the automation that watches that cell for changes to know when to start the vacuum.
I am definitely open to more elegant solutions that don't need to drag a formula down column D, but for now this one seems to do the job.

How to write latest record in Google Sheet formula and autofill?

I have a Google sheet - table 1 below and all the data is given. Table 1 data is people(VenderNo) claim that they want to join event with what data(EventStartDate) and what booth number(BoothNo). So the data is duplicated because people update it with new line and never allowd to delete or update the existing record(table 1).
Input data
And I also have a Google sheet - table 2 below and only EventStartDate and BoothNo are given. All I want to do is the result like table 2's VenderNo. The purpose of table 2 is trying to summarize which vendor is eventually joining the event with latest booth number.
Ideal result like blow:
Output data
May I know how to write this formula in table 2 column C (VendorNo) with autofill function like ={ "VendorNo"; unique(General!A2:A) } without hand dragging the formula?
Any thoughts and thank you.
P.S.: I am sorry I couldn't post image above directly because I don't have enough reputation.
Revision 1 for Mike Result: (Yellow highlight mismatched, since v001 should not join the same event date with 2 booths)
Revision 2 for Mike Result: (Yellow highlight mismatched, since v004 added to 2022-11-11 for BoothNo A01. BoothNo C01 doesn't erase as expected, Because same vendor(VendorNo) should only be with same date( EventStartDate) & latest booth selection(BoothNo))
Try
={"vendor";arrayformula(if(
iferror(vlookup(E2:E&"~"&F2:F,{B2:B&"~"&C2:C,A2:A,C2:C},3,0))
=
iferror(vlookup(vlookup(E2:E&"~"&F2:F,{B2:B&"~"&C2:C,A2:A},2,0)&"~"&E2:E,({unique({A2:A&"~"&B2:B}),(vlookup(unique({A2:A&"~"&B2:B}),SORT({A2:A&"~"&B2:B,C2:C,row(A2:A)},3,0),2,0))}),2,0),""),
iferror(vlookup(E2:E&"~"&F2:F,{B2:B&"~"&C2:C,A2:A},2,0)),""
))}
You don't need a Formula for that. Just select your columns and go to "Data" ->"Sort data"->"advanced sort settings" and then sort by column "EventStartDate" and secondly add sort by another column and add "BoothNo".
In the end you can run a data clean up to remove duplicates. You find it also under data.
to get the latest update from your table 1 you can use:
=SORTN(SORT(A2:C, B2:B, 0), 9^9, 2, 1, 1)
for your table 2 try:
={"VN"; INDEX(IFNA(VLOOKUP(E2:E&F2:F,
SORTN(SORT({B2:B&C2:C, A2:C}, B2:B, 0), 9^9, 2, 2, 1), 2, 0)))}

Google Sheets VLOOKUP formula stops working when new item values are added to the column being looked up

Hello stack overflowers.
I have recently been creating a nutrition tracker to better track and control my nutrition. However I have run into an issue. So currently I have a 1 sheet in the nutrition tracker which is a "database" of foods and their macro nutrients per gram. In this sheet, I will enter all the foods that I generally eat and their associated per G nutrients.
this food "database" sheet has the following columns.
FOOD NAME, CALORIES, PROTEIN, CARBS, OF WHICH SUGARS, FAT, OF WHICH SATURATED, FIBER, SALT
This database is then used as a reference, so that when I input each meal as I eat it, I can simply select the food from a drop down list and type the number of G in that meal, and the nutrients will all be calculated for me.
I currently have it setup so that I can select food from the drop down list generated by "foods" sheet, within each meal table I have created. This is then correctly filling in the rest of the columns as expected once I input a weight for each meal. There is however a huge problem.
As soon as the FOOD NAME column of the Foods sheet had values in it below row 7 (not sure why this row is the limit) the whole thing stops working, the data grabs based on VLOOKUP just return 0 and do not act as they are meant to. The strange thing is they work absolutely fine until I enter too many foods (7 foods) into the foods sheet.
Please find below a link to my spreadsheet, maybe you can duplicate it and play around a little yourselves to better understand the issue.
https://docs.google.com/spreadsheets/d/1orwih7s_Z4ew8G1vJcR6qlxyMpX8pqK-3Ynj42qQjcQ/edit?usp=sharing
(if you help me fix it, you will have a free nutrition tracking spreadsheet to help you take control of your diet aswell)
Thanks in advance.
In the June tab, clear all formulas in the range D11:K18.
Then enter in D11
=ArrayFormula(IF(LEN(B11:B18), IFERROR(VLOOKUP(B11:B18, FOODS!A:I, {2, 3, 4, 5, 6, 7}, 0)),))
This single formula will process all values entered in B11:B18.
Note the third parameter of VLOOKUP (set to false). If it is ommitted (as in your formula) it will default to 'true'. That means vlookup expects a 'sorted order' which may not be the case for your data.
References
VLOOKUP
try:
=INDEX(IF(B11:B18="";; IFNA(VLOOKUP(B11:B18; FOODS!A:I; COLUMN(B:G); ))))

vlookup(importrange) function doesn't find data from query result table in another spreadsheet

I've two teams. Each of those team has its own spreadsheet file they work with. I've created a new spreadsheet document that uses query(importrange) function to create a single table of all results from each team's spreadsheets.
The idea is to then use the vlookup(importrange) function in yet ANOTHER spreadsheet document to deliver specific query results. i.e. by vlookup'ing email address from the query database, import other relevant information to that email address.
I've been using this logic for a few months now and everything seemed to work fine. The only difference is that my past experience was with query result table that contained only 1 column of data.
Now, when the query result table contains 7-9 columns, this no longer seems to work.
I've concluded, that only the first column is somehow visible for the vlookup(importrange) function, while other columns seem to be invisible.
The Query result table formula:
=QUERY({IMPORTRANGE("Team A","In Progress!A:M");IMPORTRANGE("Team B","In Progress!A:M")},"where Col1 is not null",1)
The formula on another spreadsheet that should act as a verifier/checker:
=IFerror(arrayformula(VLOOKUP(D3,IMPORTRANGE("the query result's sheet","In Progress!A:G"),{1,4,6,7},0)),"-")
I really hope the problem is described clearly. I expect vlookup(importrange) to import data from query result table in another spreadsheet document.
=ARRAYFORMULA(IF(LEN(A3:A), IFERROR(VLOOKUP(A3:A,
QUERY(IMPORTRANGE("15xOcSh39zZgn1829DOYF5hB6WeuaTO81pyi6Ek3R-Gw", "Sheet1!A:H"),
"select Col2,Col1,Col3,Col4,Col5,Col6,Col7", 0), {2, 5, 6, 7}, 0), "-"), ))

Resources