How to select a preferred value from multiple rows?

Manojlo

New Member
Joined
Sep 4, 2020
Messages
42
Office Version
  1. 365
Platform
  1. Windows
Hello friends,

There is ID numbers in column A, It can be an individual entry or several entries with the same ID number
In column B, I have just two values WHITE or BLACK
In column D I identified with formulas only unique ID from column A

And now I need help with column E. In this column I want to have WHITE values from column A if it is exist in column A. If WHITE don't exist than BLACK is ok.
When I used VLOOKUP function it returns the first value from the list (from column A), and for example for ID 6666 VLOOKUP returns in column E value BLACK (because BLACK is above WHITE in column A), but I want to see WHITE because it exist.

Thank you in advance.

1672144044051.png
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
VLOOKUP always returns the FIRST match it finds.
So one simple way to address your issue is to simply sort your original data, first by ID, and then second by Color, but in DESCENDING order, so the WHITE entries always appear before the BLACK ones.

Alternatively, you could use an IF functions with COUNTIFS to see if there are any white or black entries for that particular ID, by sorting is a quicker/shorter solution.
 
Upvote 0
VLOOKUP always returns the FIRST match it finds.
So one simple way to address your issue is to simply sort your original data, first by ID, and then second by Color, but in DESCENDING order, so the WHITE entries always appear before the BLACK ones.

Alternatively, you could use an IF functions with COUNTIFS to see if there are any white or black entries for that particular ID, by sorting is a quicker/shorter solution.
Thank you, yes I know that sort (filtering) is one of the solution, but I was looking if there any solution with formula.
 
Upvote 0
Note that Sorting and Filtering are NOT the same thing! They are two very different things!
If you simply sort the data like I suggested, your VLOOKUP formula will work fine.

As long as the values in column D always exist in column A (which sounds like they should, since you seem to be deriving them from your list in column A), then you can use this formula to get what you want (place in cell E2 and copy all the way down to cell E7):
Excel Formula:
=IF(COUNTIFS(A$2:A$11,D2,B$2:B$11,"WHITE")>0,"WHITE","BLACK")
 
Upvote 0
Solution
Note that Sorting and Filtering are NOT the same thing! They are two very different things!
If you simply sort the data like I suggested, your VLOOKUP formula will work fine.

As long as the values in column D always exist in column A (which sounds like they should, since you seem to be deriving them from your list in column A), then you can use this formula to get what you want (place in cell E2 and copy all the way down to cell E7):
Excel Formula:
=IF(COUNTIFS(A$2:A$11,D2,B$2:B$11,"WHITE")>0,"WHITE","BLACK")
Thank you very much, this is solution I was looking for.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,649
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top