VLookup Displaying Duplicate Values - Google Sheets - google-sheets

I've created a lookup formula to take values from column E, match them with values in column A, and assign the corresponding value found in column C and populate it in column F.
I've checked for duplicates in E and A, but I'm still seeing duplicates in F. It's not because there isn't a match, I've checked that as well.
My formula is:
=LOOKUP(E2, $A$2:$A$121, $C$2:$C$121)
Here is a simplified version of the spreadsheet: https://docs.google.com/spreadsheets/d/1A-S0nHFIUGycaDo7KDPAzWBwRZQmfxkjaMivwGfBh-8/edit?usp=sharing

delete everything in F column and use in F2:
=INDEX(IFNA(VLOOKUP(E2:E, A:C, 3, 0)))

Related

Google Sheets formula to lookup value for all rows in another sheet by column names and returning value by column name

I have a Sheet1 with data like this:
one
two
three
four
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
I have Sheet2 with data like this:
alpha
value 1
c
k
g
c
For each row in Sheet2, I want to look up Sheet2.A2:A in Sheet1 according to a lookup column name in Sheet1 and returning values from the associated row in Sheet1 by return column name in Sheet1.
So, a few examples:
Lookup Sheet2.A2:A in Sheet1.three and return Sheet1.one
Lookup Sheet2.A2:A in Sheet1.two and return Sheet1.four
The idea is the formula would specify the lookup column name and return column name and I'd just change it for each lookup I need to do.
Imagine the formula was something like:
=ARRAYFORMULA(
SOMEFORMULA(
A2:A, # lookup this value
GETCOLUMN(Sheet1, "three"), # in this column in Sheet1
GETCOLUMN(Sheet1, "one") # and return the value from this column in Sheet1
)
)
So, the expected result is:
alpha
value
c
a
k
i
g
e
c
a
I can use the new Google Sheet formulas they just released -- except named ranges. I feel like there is some clever trick using them, but I can't come up with it.
Give a try on below formula:
=BYROW(A2:INDEX(A2:A,COUNTA(A2:A)),LAMBDA(x,INDEX(Sheet1!A:D,MATCH(x,INDEX(Sheet1!A:D,,MATCH("three",Sheet1!A1:D1,0)),0),MATCH("one",Sheet1!A1:D1,0))))
By XLOOKUP() function.
=BYROW(A2:INDEX(A2:A,COUNTA(A2:A)),LAMBDA(x,XLOOKUP(x,FILTER(Sheet1!A2:D,Sheet1!A1:D1="three"),FILTER(Sheet1!A2:D,Sheet1!A1:D1="one"),"")))
Sample Sheet Link.
Use HLOOKUP to the get the correct column in Sheet1 and XLOOKUP to get the corresponding column A value:
=ARRAYFORMULA(
XLOOKUP(
A2:INDEX(A2:A,COUNTA(A2:A)),
HLOOKUP("three",Sheet1!A1:Z,SEQUENCE(ROWS(Sheet1!A1:Z)),0),
Sheet1!A1:A
)
)

vlookup get latest match of duplicates

I'm trying to display a filtered version of sheet1 data in sheet2:
Sheet1:
Sheet2:
I used vlookup on sheet2 columns C,D,E to display sheet1 columns B,D,A respectively.
i.e., Sheet 2 - Column C
=vlookup(A2,Sheet1!A3:D,3)
but I'm not sure how to make it work with duplicates and to only get the latest one.
I tried using vlookup on query result but it didn't work out (because I was referencing a reference?)
=sortn(query(Sheet1!A2:D6,"select * where A is not null order by B,A desc"),99^99, 2, 2, true)
How can I apply vlookup to get the latest match of duplicate rows? If it's not possible, how can I go about this (if possible, without having to add extra sheets)
If I wanted to use Vlookup and Query to do it, I would end up with something like this:
=ArrayFormula(vlookup(query(B2:B,"select min(B) where B is not null group by B label min(B) ''"),
query(A2:D,"select B,A,C+D,C,D where A is not null order by B,A"),{2,1,3,4,5}))
so the first query gets the unique values of column B, and the second query gets the original data plus total (C+D) sorted in ascending order of family name then timestamp. Then vlookup finds the last matching value for each family name, which in this case is the latest one. You could also sort on timestamp descending and use the exact form of vlookup to find the first occurrence - probably a little bit slower:
=ArrayFormula(vlookup(query(B2:B,"select min(B) where B is not null group by B label min(B) ''"),
query(A2:D,"select B,A,C+D,C,D where A is not null order by B,A desc"),{2,1,3,4,5},0))
In reality I would probably use sort and sortn as I think you started to do in your question:
=sortn(sort(filter({A2:B,C2:C+D2:D,C2:D},A2:A<>""),2,1,1,0),999,2,2,1)
This time it's sorted on family name ascending then timestamp descending, then sortn removes duplicates.
use in row 2:
=INDEX(IFNA(VLOOKUP(A2:A, SORT(Sheet1!A:D, ROW(Sheet1!A:D), 0), 3, 0)))

Vlookup on partial match

Sample Sheet: https://docs.google.com/spreadsheets/d/16HUbIpN9MfTh5msRl54wMCRddTdKUyST-2XqNsnaPxs/edit?usp=sharing
I need to vlookup on a partial match in the search key. In the attached speed sheet, the search key in column A. If the search key in column A contains the lookup value in column F, the value in column G should be returned in column B.
I would prefer to do it with an array formula because my actual sheet is huge. Your help will be greatly appreciated!
In B2 try
=ArrayFormula(if(len(A2:A), iferror(vlookup(regexextract(A2:A, textjoin("|", 1, F2:F)), F:G, 2, 0)),))
and see if that works?
Regexextract 'extracts' the part of the search key (column A) that matches the vlookup value (column F).
Then, the extracted part is used in Vlookup() to retrieve the value (column G).

How do I add to my QUERY function to add an additional requirement?

=ARRAYFORMULA({
AVERAGE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(Data!D$2:E856<>"", "♠"&Data!D$2:E856&"♦"&Data!F$2:G856, )),,999^99)),,999^99), "♠")), "♦"),
"select Col2
where lower(Col1) contains '"&LOWER(A2)&"'
offset "&COUNTIF(Data!D$2:E856, A2)-6))})
I have the above formula that I am using. What this does is the following:
The last 6 times A2 shows up in either Column D or E, it accumulates the corresponding value in column F or G. Those 6 values are then turned into an average, as well.
I am trying to add one condition to this. I want it to only take those last 6 instances where column H and I are also something specific.
So when A2 shows up in column D, I only want to use the row if Column I is the value "X". When A2 shows up in column E, I only want to use the row if Column H is "X".
I am unable to get this implemented into my function myself and desperate for some help. One problem is that the "X" search is in reversed column order (ie. when A2 is in D, trying to search I...and when A2 is in E, trying to search G...which isn't the order those appear in the alphabet). Also just not sure where in formula this conditional even needs to go.
Data! just references the sheet I have my dataset dumped into, obviously.

How to Count Duplicate values based on other cell values in google sheet

How can I count Duplicates values based on other cell values look bellow
I have 3 duplicates in Column B but in Column C only 2 duplicates vales mention So I want to count remain duplicate Values in Column B which are not mentioned yet in Column C or in other words I want to count column B duplicates values which have an empty cell in Column C.
Look into Column D which get value 1 as we have only duplicate value in column B which have an empty cell in column C.
Hope you got my point.
try:
=ARRAYFORMULA(SUM(N(COUNTIFS(B2:B, B2:B, ROW(B2:B), "<="&ROW(B2:B))>1))-
COUNTIF(C2:C, "Duplicate"))
or:
=ARRAYFORMULA(SUM(N(FILTER(COUNTIFS(B2:B, B2:B, ROW(B2:B), "<="&ROW(B2:B))>1, C2:C=""))))

Resources