Handling Duplicate Values

mskusace

New Member
Joined
Jan 2, 2019
Messages
18
I have a lookup table that looks like the table below. It is truncated and masked to simplify the problem, but the logic will be the same.

IDCODEREASSIGN(CODE)
W12-05AAZZ
W12-05BBZZ
W14-01CCCC
W14-03AAAA
W15-01DDDD
W15-01DDDD

<tbody>
</tbody>

ID and CODE are generated from the report
REASSIGN(CODE) is what I am trying to accomplish. If there are multiple IDs (ex. W12-05) that are the same with different CODE values, then assign it to "ZZ" . However, if there are multiple IDs and they all have the same CODE values (ex. W15-01), then assign it to the same code value.

My other data set has ID with some other values, but I need to use the lookup table to get the REASSIGN(CODE).

IDLOOKUP REASSIGN(CODE)
W12-05ZZ
W14-01CC
W14-03AA
W15-01DD

<tbody>
</tbody>

This way, even if there are multiple instances of an ID, as long as each ID has the same code the VLOOKUP will pull the correct value no matter which one it selects.

How can I accomplish the REASSIGN(CODE) column in the first table? Something along the lines of:
If IDs duplicate and multiple different CODEs, assign to ZZ.
If IDs duplicate and same codes, assign to same CODE.

There might be instances where if there certain multiple codes for duplicate IDs, it will need to assign to a specific CODE. "ZZ" is the default when I don't know where it should go and it can be handled by another department. Sometimes I know that code "EE" and code "FF" belong to one department and there is logic to assign it to "GG" for example.

I am open to suggestions and ideas, even if much different than my presented solution. Any assistance would be greatly appreciated.

Please let me know if you need any clarification!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How about


Excel 2013/2016
ABC
1IDCODEREASSIGN(CODE)
2W12-05AAZZ
3W12-05BBZZ
4W14-01CCCC
5W14-03AAAA
6W15-01DDDD
7W15-01DDDD
A1
Cell Formulas
RangeFormula
C2=IF(COUNTIF($A$2:$A$7,A2)<>COUNTIFS($A$2:$A$7,A2,$B$2:$B$7,B2),"ZZ",B2)
 
Upvote 0
Maybe something like this...


A
B
C
D
E
F
1
ID​
CODE​
REASSIGN(CODE)​
ID​
LOOKUP REASSIGN(CODE)​
2
W12-05​
AA​
ZZ​
W12-05​
ZZ​
3
W12-05​
BB​
ZZ​
W14-01​
CC​
4
W14-01​
CC​
CC​
W14-03​
AA​
5
W14-03​
AA​
AA​
W15-01​
DD​
6
W15-01​
DD​
DD​
7
W15-01​
DD​
DD​
8

Formula in C2 copied down
=IF(COUNTIF(A:A,A2)<>COUNTIFS(A:A,A2,B:B,B2),"ZZ",VLOOKUP(A2,E:F,2,0))

Hope this helps

M.
 
Upvote 0
Thank you both for the replies. It appears to be working in most cases; however, I am getting some results as "0". I am not sure where the zero is showing up or why. Any possible reasons?
 
Upvote 0
It looks like Excel isn't updating the formula. I have automatic calculation on and 222,465 rows of data. I even copied the data and pasted it as values into a new spreadsheet to eliminate any other calculations. I have to double click each cell and then select enter. Am I exceeding my computer and Excel's calculation power? Should I look at SQL for this? If so, any recommendations on how to convert that to a SQL query?
 
Upvote 0
For that amount of data it will probably take a bit of time to calculate.
I know nothing about SQL or Power BI, so don't know if they would be better
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,672
Members
449,045
Latest member
Marcus05

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