How to update data in a Google sheet depending upon another sheet? - google-sheets

I need to update a cell with a defined value automatically by comparing and referencing this data from another Google sheet.
In Sheet1 Column_C is to be updated by comparing Column_A in Sheet1 to Column_A in Sheet2.
If it is a match, and Column_B's value from Sheet2 is 1, then the result should be "issued", otherwise it should be "in-stock".
Sharing google sheet link :
https://docs.google.com/spreadsheets/d/1h_D5u16ye1CA6C7dideJVZoV8cBvZB8M3RRxXBANsf4/edit?usp=sharing
How can I accomplish this using Google Sheets?

Try this in cell C1 (delete all other values below):
=arrayformula({"Status";if(A2:A<>"",substitute(substitute(iferror(vlookup(A2:A,filter(sheet2!A:B,countifs(sheet2!A:A,sheet2!A:A,row(sheet2!A:A),">="&row(sheet2!A:A))=1),2,0),),1,"Issued"),0,"In-Stock"),)})
To handle items in sheet1 that are not in sheet2, you can add a value in the iferror function (the first "In-Stock" below):
=arrayformula({if(A2:A<>"",substitute(substitute(iferror(vlookup(A2:A,filter(sheet2!A:B,countifs(sheet2!A:A,sheet2!A:A,row(sheet2!A:A),">="&row(sheet2!A:A))=1),2,0),"In-Stock"),1,"Issued"),0,"In-Stock"),)})
This is responsible for getting the dataset from sheet2:
filter(sheet2!A:B,countifs(sheet2!A:A,sheet2!A:A,row(sheet2!A:A),">="&row(sheet2!A:A))=1)
This part gets the instance number of each duplicate value in sheet2!A:A:
countifs(sheet2!A:A,sheet2!A:A,row(sheet2!A:A),">="&row(sheet2!A:A))
Where there are duplicate values, ">=" gets the one furthest down the sheet. Changing it to "<=" will get the first instance at the top of the sheet.
Within filter, countifs(sheet2!A:A,sheet2!A:A,row(sheet2!A:A),">="&row(sheet2!A:A))=1) filters the column to show just 1 instance of each value in sheet2!A:A.
Looking at your example sheet, you have these values in row 6, 7, 8, so the first instance (ascending or descending) will be 0:
1230E 0
1230E 1
1230E 0
If you're looking for a different logic, like 1 trumps 0, then you'll need to apply a sort on the data before performing the vlookup. Something like:
=arrayformula({if(A2:A<>"",substitute(substitute(iferror(vlookup(A2:A,unique(sort(sheet2!A2:B,1,1,2,0)),2,0),"In-Stock"),1,"Issued"),0,"In-Stock"),)})

Related

Google Sheet ISBETWEEN doesn't recognize named range?

Column A is named "Quantity", which works in a simple formula:
I'm getting an error when attempting to use a named range in ISBETWEEN formula:
I verified that ISBETWEEN works when I use cell reference A2 instead of named range Quantity:
Any thoughts how I can fix? 😤
Your named range Quantity has its range set to A1:A but you are entering it in row 2, so error says there is no room in A2:A for A1:A unless you add a row but when you do it's the same coz you can't fit 3 keys into 2 keyholes (from one side each of course)
As seen on this sample:
See my comment to your original post.
Assuming that your named range Quantity is applied to the entire range A:A (and not A2:A), delete everything from Col B (including the header) and then place the following formula in cell B1:
=ArrayFormula( {"Test"; IF(A2:A="",, ISBETWEEN( FILTER(Quantity, ROW(Quantity)>1), 1, 5) ) } )
This one formula will create the header text (which you can change within the formula if you like) and all results for all valid, non-null rows.
FILTER(Quantity, ROW(Quantity)>1) is necessary to limit the full range of the named range Quantity to only those elements whose row is greater than (row) 1; this is because your results begin in Row 2.
You only need this one formula. As you add more data into Col A, the formula will process it.

Incrementing a column in a group using an Array Formula in Google Sheets

I am having difficulties trying to get an array formula to increment a column and restart the increment whenever a condition has been met.
Here is an example of what I am trying to achieve, but this has been done manually. It would be great if this could work in an array formula as we'll be adding more rows and would rather not drag the formula down.
[Update based on feedback of the original post]
Column A contains a list of names and teams.
Names are already organised into teams.
The aim is to go through each row and provide a name with an index starting from 1.
Then when a new team is found in column A the index starts again from 0.
The aim is to make this an Array Formula to avoid having to manually re-add the formula when more rows are added.
Link to sheet:
https://docs.google.com/spreadsheets/d/1K00LRFNrN99fFXQO1tzp8jjZeCuTxwENXNGuLj0K0ao/edit?usp=sharing
Example
Any thoughts or advice on this would be greatly appreciated.
I've added a new sheet ("Erik Help") to your sample spreadsheet. It contains the following formula in B1:
=ArrayFormula({"ID Index"; IF(A2:A="",, IF( REGEXMATCH(LOWER(A2:A),"team"), 0, ROW(A2:A) - VLOOKUP(ROW(A2:A), FILTER(ROW(A2:A), REGEXMATCH(LOWER(A2:A),"team")), 1, TRUE)))})
The header text is included in the formula. You can change it as you like.
If a cell in A2:A is blank, the corresponding cell in B2:B will be as well.
If REGEXMATCH finds a match with "team" in the lowercase rendering of a cell in A2:A, 0 will be returned for the corresponding cell in B2:B.
Otherwise, VLOOKUP will lookup each remaining row number in a FILTERed array containing only those row numbers where the word "team" appears. (In your sample set, that will be 2, 8, 12). When the exact match is not found (which it will not be for any remaining row), TRUE tells VLOOKUP that, since the search array is in strict ascending order, we want it to "bump back" to the most recent value found. In each case, the returned row number of the most recent row containg "team" is then subtracted from the actual row number to produce the recurring incremental numbering 1, 2, 3, etc.
try:
=INDEX(IFNA(1*IF(REGEXMATCH(A2:A, "Day"), 0, REGEXEXTRACT(A2:A, "(\d+)"))))

In Google Sheets, I want to populate cells in Column A with certain conditions, based on the contents of column B

In this sheet,
https://docs.google.com/spreadsheets/d/1MR0n1FoutASbuwiNJS7FrcQhxHF6Bo03oVs9RZPo9g4/edit?usp=sharing
I am trying to have column B be populated with cell values equal to is today's date or tomorrow's date, by referencing column F.
Then, I am trying to have column A be populated with the contents of column E, based on if the column E's item is for today or tomorrow (Basically if the item's corresponding date shows up in B).
I've tried playing with index, lookup and filter but I cannot manage to get the formula right, and when using index and lookup there are many empty cells in between the dates.
I would appreciate any help.
I added a sheet ("Erik Help") with the following formula in A1:
=ArrayFormula(IFERROR(FILTER(E:F,(F:F=TODAY())+(F:F=TODAY()+1))))
That one formula returns all results you wanted to see.
Explanation:
The key part to understand is the condition that FILTER is using to filter in entries; and that is (...) + (...). The plus sign is the equivalent of OR in an array. So it's basically saying, "Filter in all results from E:F where (F:F = today) OR (F:F = tomorrow)." And if there is no match at all found for that OR condition, IFERROR will just return nothing (rather than an error).
Reference:
FILTER

Query and ImportRange with Dynamic Values

I have 2 sheets which are connected.
Sheet-1: Has ID column and Status column (Status field is manually updated by the team)
Sheet-2: Has ID column and Status column (+ many other fields)
Requirement: Status column in Sheet 2 to be updated from Sheet-1 if ID column in sheet-2 = ID column in Sheet-1
I wrote a Query and ImportRange, but I could find Query working only when I compare it against a static value (for e.g. Yes). What I want is it to check against the value in ID column from both the sheets and import only for rows that match.
=QUERY(IMPORTRANGE("1ZkPaYb1IIIkcbVerdmZ-Ru1vxFu1YMWj74QNQj2jles", "Ops Action Sheet!B2:B10000"),"select Col2 where Col1 = 'Yes'")
This doesn't directly answer your question about using QUERY, but I believe that that function might not be the best tool for what you're trying to do.
I write below a solution using the alternative function VLOOKUP.
I am assuming here that by "Sheet-1" and "Sheet-2", you actually mean entirely different spreadsheets, judging by your use of IMPORTRANGE.
If you don't mind having a copy of Sheet-1's contents living within Sheet-2, here is what you can do:
On a new sheet (tab) in Sheet-2, copy this function (fill in sheet_1_url):
=IMPORTRANGE("sheet_1_url", "Ops Action Sheet!$A:$B")
You should see a copy of the data from Sheet-1 in that tab. You can hide this tab or protect it if you wish.
On your main data tab within Sheet-2, copy this formula in your Status column (assuming that your ID is in A2:
=IFERROR(VLOOKUP($A2,range_from_step_1,2,),)
Copy that formula down as much as you need.
However, if you don't want to have a copy of Sheet-1's data in Sheet-2 for whatever reason, you can simply skip steps 1-2 above, going straight to step 3, with the following formula in Sheet-2:
=IFERROR(VLOOKUP($A2,IMPORTRANGE("sheet_1_url", "Ops Action Sheet!$A:$B"),2,),)
Not that I recommend it, since you'd technically be importing your data virtually within the formula N number of times, which will be a huge performance hit.
You can see the references for the formulas used above here:
IMPORTRANGE
VLOOKUP
IFERROR
edit to reflect and paste in spreadsheet 2:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, IMPORTRANGE("ID", "Sheet!A:C"), {2, 3}, 0)))
A2:A - column of IDs in spreadsheet 2
Sheet!A:C - column A of this range hosts IDs
{2, 3} - brings column B and C from spreadsheet 1 into spreadsheet 2

Sort the value of a column with a relative position (using an other column data order)

I've created a form to collect data from user A in a sheet and reformat it for user B in the other sheet.
I have to sort the data for user B. I'm using vlookup to sort the column of values from the form to a new sheet (sort based on the order of the 'value description column'). It's working.
My problem is that when a new column is added to the first sheet (the form) the column range is modified and the index parameter in vlookup is not good anymore. So I lost everything on my second sheet.
How can I do to have a solid link with the column in the first sheet even if it's position change?
you can make use of INDIRECT with COUNTA and SUBSTITUTE. something like:
=INDIRECT("Sheet1!A1:"&SUBSTITUTE(ADDRESS(1, COUNTA(Sheet1!1:1), 4), 1, "")
this will count non-empty cells in row 1 of Sheet1 and converts that number to later which is used in constructing the range put together by indirect formula and all of it can be placed in vlookup as same as you would place any ther regular range.

Resources