Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

google sheets - How to get last value from VLookup?

I know this has been asked a number of times, but I haven't quite found an answer that fits my situation. I've tried using INDEX and the TRUE value, but it doesn't seem to working for me. I also tried changing the columns (DATE, then ITEM and COST), but to no avail.

I am using GOOGLE SHEETS.

The workbook has two sheets, this one is called Reference. The one it calls is called Sales. The data is UNSORTED by item, but is sorted by date, though duplicate instances may exist. I am using this formula:

=VLOOKUP(A2,Sales!A:C,3,false)

It works, but it calls the FIRST value. I need the LATEST value. It needs to go through the entire COLUMN to search for this value, then return the corresponding (latest) value on the third column. Both sheets have ITEM column; the purpose of Reference is to check if there is a match for the item existing on the Sales sheet and, if it's there, refer to the latest value "COST". Because numerous instances of ITEM and COST are in sales with differing values, I need to call up the latest number.

In addition, I have another formula that calls data from another sheet, in another workbook, that does virtually the same thing:

=VLOOKUP(A2,importrange("https://docs.google.com/spreadsheets/d/URL/","Sales!A:C"),3,false)

Again, it works at getting the value I need, just not the LATEST value. The sheet is formatted like this:

(SALES)
ITEM     DATE     COST
A2       B2       C2
A3       B3       C3

The reference sheet is like so:

(REFERENCE)
ITEM     LOOKUP
A2       B2
A3       B3

Any help you can offer would be greatly appreciated.

question from:https://stackoverflow.com/questions/66057154/how-to-get-last-value-from-vlookup

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

all you need to do is sort it in descending order either based on dates or rows (based on your preferences / needs)

example:

=VLOOKUP(A2, SORT(Sales!A:C, 1 +N("1st column contains dates"), 0 +N("descending")), 3, )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...