Find duplicate data from pair cells and then pick and put a value only to one of them (date/hour criteria)

komhs

New Member
Joined
Jun 12, 2016
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone and thanks in advance for the help.

My main goal is to fill with formula the J column with the values of I column. With a few words if we don't have "duplicate rows" we just fill the J with the value of I. If we have "duplicate rows" (A and E are the basic criteria) we are looking at Date and Time and we pick the value from I according to date and time (if there is time difference we pick the the earliest) or (if they have same date and time) we pick the highest value.

ABCDEFGHIJ
1CheesePriceAPriceBPriceCTypeAF.DateTimeVSPick
2Mozzarella396392397Goncalo27,54 %2/11/202114:58-0,5-0,5 (it is not duplicate)
3Cottage291290260Kabylie26,32 %2/11/202115:582,12,1 (duplicate with row 5, but the time is earliest)
4Cottage334331337Shamal18,87 %2/11/202113:5800 (not duplicate)
5Cottage360360361Kabylie16,67 %2/11/202116:581,24(empty cell because it was duplicate with row 3 and the row 3 had earliest time)
6Ricotta377368371Leeds14,29 %2/11/202115:58-0,75-0,75 (duplicate with rows 7 and 8, they had the same Time Date, BUT we have a value because this row had the highest value (from 0,75, -1, -1) of the specific cells in column I)
7Ricotta268268269Leeds10,53 %2/11/202115:58-1(empty cell because it was duplicate with row 6, 8 and the row 6 had the highest value)
8Ricotta268268269Leeds10,53 %2/11/202115:58-1(empty cell because it was duplicate with row 6, 7 and the row 6 had the highest value)

The key is to fill with values the J column, according to the criteria of duplicate rows and Date Time.
Key columns and explanation:
Cheese and Type (A and E): With these two as a pair we are trying to find if there are duplicate values ("as rows") to the dataset A1:J8. For example: The Rows 3 and 5 are not similar (they have different values in most of the cells), BUT from the moment that the name of Column A3 (Cottage) and A5 (Kabylie) and E3 (Cottage) and E5 (Kabylie) are similar, for us are duplicate rows. In A4 we have a similar Value (Cottage) with A3 and A5, but the E4 is not the same, so they are not duplicates.
VS (I): This is the value that we must pick and send or not send to Pick if the criteria has been met.
Pick (J): Here is where we fill or not fill the value (we are taking this value from VS), if the criteria has been met.
Date and Time (G and H): If we have duplicate values (when they exist from the pair of Cheese and Type) we pick from VS the one which is the earliest, as you can see in J4 and we leave empty the other (J5). We have set as duplicates rows 3 and 5 because they have same name in column A and same name in column E, and we have picked the VS from I3, because row 3 has 15:58 time and row 5 has 16:58.
If we have duplicates and they have the same date and time (rows 6, 7, 8 are duplicates with same date and time) we pick the one with the highest value
If
there are no duplicated values (like row 2 and row 4) we don't use this criteria. We just pick from VS the value and put it to Pick.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try:

Book2
ABCDEFGHIJ
1CheesePriceAPriceBPriceCTypeAF.DateTimeVSPick
2Mozzarella396392397Goncalo27,54 %2/11/202114:58-0.5-0.5
3Cottage291290260Kabylie26,32 %2/11/202115:582.12.1
4Cottage334331337Shamal18,87 %2/11/202113:5800
5Cottage360360361Kabylie16,67 %2/11/202116:581.24 
6Ricotta377368371Leeds14,29 %2/11/202115:58-0.75-0.75
7Ricotta268268269Leeds10,53 %2/11/202115:58-1 
8Ricotta268268269Leeds10,53 %2/11/202115:58-1 
90
Sheet10
Cell Formulas
RangeFormula
J2:J9J2=IF(COUNTIFS(A$2:A2,A2,E$2:E2,E2)>1,"",AGGREGATE(14,6,$I$2:$I$100/($A$2:$A$100=A2)/($E$2:$E$100=E2)/($G$2:$G$100+$H$2:$H$100=AGGREGATE(15,6,($G$2:$G$100+$H$2:$H$100)/($A$2:$A$100=A2)/($E$2:$E$100=E2),1)),1))



Edit: I changed the formula a bit. Can we say that you want the highest value from the earliest time of any duplicates? That seems to be equivalent to what you said, and it makes the formula easier.
 
Last edited:
Upvote 0
Solution
Try:

Book2
ABCDEFGHIJ
1CheesePriceAPriceBPriceCTypeAF.DateTimeVSPick
2Mozzarella396392397Goncalo27,54 %2/11/202114:58-0.5-0.5
3Cottage291290260Kabylie26,32 %2/11/202115:582.12.1
4Cottage334331337Shamal18,87 %2/11/202113:5800
5Cottage360360361Kabylie16,67 %2/11/202116:581.24 
6Ricotta377368371Leeds14,29 %2/11/202115:58-0.75-0.75
7Ricotta268268269Leeds10,53 %2/11/202115:58-1 
8Ricotta268268269Leeds10,53 %2/11/202115:58-1 
90
Sheet10
Cell Formulas
RangeFormula
J2:J9J2=IF(COUNTIFS(A$2:A2,A2,E$2:E2,E2)>1,"",AGGREGATE(14,6,$I$2:$I$100/($A$2:$A$100=A2)/($E$2:$E$100=E2)/($G$2:$G$100+$H$2:$H$100=AGGREGATE(15,6,($G$2:$G$100+$H$2:$H$100)/($A$2:$A$100=A2)/($E$2:$E$100=E2),1)),1))



Edit: I changed the formula a bit. Can we say that you want the highest value from the earliest time of any duplicates? That seems to be equivalent to what you said, and it makes the formula easier.

First of all thank you so much for the reply.
Secondly, am I doing something wrong? It generates #value! for some reason
 

Attachments

  • Capture55.PNG
    Capture55.PNG
    49.9 KB · Views: 8
Upvote 0
First of all thank you so much for the reply.
Secondly, am I doing something wrong? It generates #value! for some reason
I found what was wrong. Thank you so much!
 
Upvote 0
Glad you figured it out! But after I posted my original formula, I thought of a potential problem, and posted a revised, shorter version. See if that works for you, and check the question I put in post #2. The problem was that if there is an earlier time for a particular set, that is not the first row of that set, then the answer would be wrong.
 
Upvote 0
First of all thank you so much for the reply.
Secondly, am I doing something wrong? It generates #value! for some reason
In some points of the data is generating a #NUM error. I placed it in a long dataset and for some reason I get a #NUM!
 
Upvote 0
Which version of the formula are you using? Can you post it? Can you post your data? Not necessarily all of it, but all of the relevant rows that are referenced when calculating the formula that gives the #NUM. Ideally, it's best if you can use the XL2BB tool to post the data instead of just a screen print (see the link in my signature).
 
Upvote 0
Which version of the formula are you using? Can you post it? Can you post your data? Not necessarily all of it, but all of the relevant rows that are referenced when calculating the formula that gives the #NUM. Ideally, it's best if you can use the XL2BB tool to post the data instead of just a screen print (see the link in my signature).
Book3
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
2
3
4CheesePriceAPriceBPriceCTypeAF.DateTimeVS1st FORMULA2nd FORMULA
530Nov 02, 20:00Campeonato Brasileiro U20Final TimePerolas Negras U202,382,003,803,802,202,70Sao Goncalo U2027,54 %2/11/202115:582,382,00####3,803,800,0%2,202,70####1####111
600Nov 02, 16:00Premier LeagueFinal TimeAl Ittihad Kalba5,754,504,003,801,451,60Al Ahli Dubai26,32 %2/11/202115:585,754,50####4,003,80-5,0%1,451,60####1####-1-1-1
700Nov 03, 16:15Stars LeagueFinal TimeAl Ahli Doha1,751,923,653,503,653,15Al Shamal SC18,87 %2/11/202115:581,751,929,7%3,653,50-4,1%3,653,15####2####-1-1-1
800Nov 02, 16:00Ligue 1Final TimeOlympique Medea2,102,402,882,753,403,00JS Kabylie16,67 %2/11/202115:582,102,40####2,882,75-4,5%3,403,00####2####-1-1-1
953Nov 02, 21:00Checkatrade TrophyFinal TimeSalford City1,902,203,753,453,102,80Leeds United U2114,29 %2/11/202115:581,902,20####3,753,45-8,0%3,102,80-9,7%2-9,7%-1-1-1
1011Nov 02, 21:45Checkatrade TrophyFinal TimePlymouth Argyle2,002,103,753,752,902,70Arsenal U2110,53 %2/11/202116:152,002,105,0%3,753,750,0%2,902,70-6,9%2-6,9%-1-1-1
1111Nov 02, 21:45League 1Final TimeCharlton Athletic3,804,103,503,602,001,90Rotherham United10,00 %2/11/202116:153,804,107,9%3,503,602,9%2,001,90-5,0%2-5,0%-1-1-1
1210Nov 03, 07:00J2 LeagueFinal TimeKyoto Sanga1,751,753,403,604,604,25Omiya Ardija9,72 %2/11/202116:151,751,750,0%3,403,605,9%4,604,25-7,6%2-7,6%-1-1-1
1341Nov 02, 17:00CupFinal TimeWidzew Lodz1,401,284,305,106,758,50GKS Jastrzebie30,00 %2/11/202116:151,401,28-8,6%4,305,10####6,758,50####1-8,6%0,280,280,28
1413Nov 03, 14:30CupFinal TimeGKS Tychy3,153,803,503,602,001,75Wisla Krakow25,00 %2/11/202116:153,153,80####3,503,602,9%2,001,75####2####0,750,750,75
1500Nov 03, 16:15Stars LeagueFinal TimeAl Ahli Doha1,751,923,653,503,653,15Al Shamal SC18,87 %2/11/202116:311,751,929,7%3,653,50-4,1%3,653,15####2####-1  
1630Nov 02, 20:00Campeonato Brasileiro U20Final TimePerolas Negras U202,232,003,803,802,352,70Sao Goncalo U2018,70 %2/11/202116:312,232,00####3,803,800,0%2,352,70####1####1  
17Nov 06, 15:00Serie BFinal TimeUS Alessandria2,853,103,203,302,502,25Ternana16,67 %2/11/202116:312,853,108,8%3,203,303,1%2,502,25####2####  #NUM!
1821Nov 02, 18:15Premier LeagueFinal TimeAjman Club6,504,754,003,601,401,60Al Jazira Abu Dhabi31,82 %2/11/202116:316,504,75####4,003,60####1,401,60####1####3,753,753,75
1941Nov 02, 17:00CupFinal TimeWidzew Lodz1,401,284,305,106,758,50GKS Jastrzebie30,00 %2/11/202116:311,401,28-8,6%4,305,10####6,758,50####1-8,6%0,28  
2013Nov 03, 14:30CupFinal TimeGKS Tychy3,153,803,503,602,001,75Wisla Krakow25,00 %2/11/202116:313,153,80####3,503,602,9%2,001,75####2####0,75  
2100Nov 03, 16:15Stars LeagueFinal TimeAl Ahli Doha1,751,923,653,503,653,15Al Shamal SC18,87 %2/11/202117:221,751,929,7%3,653,50-4,1%3,653,15####2####-1  
22Nov 06, 15:00Serie BFinal TimeUS Alessandria2,853,103,203,302,502,25Ternana16,67 %2/11/202117:222,853,108,8%3,203,303,1%2,502,25####2####   
23Nov 06, 15:00Super League WomenFinal TimeKAA Gent Women3,754,203,753,951,651,55Club Brugge Women15,38 %2/11/202117:223,754,20####3,753,955,3%1,651,55-6,1%2-6,1% #NUM!#NUM!
2413Nov 03, 14:30CupFinal TimeGKS Tychy3,802,903,603,751,752,00Wisla Krakow32,14 %2/11/202117:223,802,90####3,603,754,2%1,752,00####1####-1  
2521Nov 02, 18:15Premier LeagueFinal TimeAjman Club6,504,754,003,601,401,60Al Jazira Abu Dhabi31,82 %2/11/202117:226,504,75####4,003,60####1,401,60####1####3,75  
2623Nov 02, 19:00CupFinal TimeBlau-Weiss Linz2,502,103,353,402,503,00TSV Hartberg26,67 %2/11/202117:222,502,10####3,353,401,5%2,503,00####1####-1-1-1
27Nov 06, 15:00Super League WomenFinal TimeKAA Gent Women3,754,203,753,951,651,55Club Brugge Women15,38 %2/11/202117:223,754,20####3,753,955,3%1,651,55-6,1%2-6,1%   
28Nov 06, 15:00Super League WomenFinal TimeKAA Gent Women3,754,203,753,951,651,55Club Brugge Women15,38 %2/11/202117:223,754,20####3,753,955,3%1,651,55-6,1%2-6,1%   
2911Nov 03, 06:05J LeagueFinal TimeKawasaki Frontale1,601,753,803,655,104,25Urawa Red Diamonds20,73 %2/11/202120:201,601,759,4%3,803,65-3,9%5,104,25####2####-1-1-1
3017Nov 04, 04:00Premier LeagueFinal TimeKhangarid Klub4,755,604,254,701,501,38Ulaanbaatar FC24,00 %3/11/202116:064,755,60####4,254,70####1,501,38-8,0%2-8,0%0,380,380,38
31Nov 06, 17:00FA CupFinal TimeKings Lynn Town3,503,403,504,001,951,85Walsall10,53 %3/11/202120:273,503,40-2,9%3,504,00####1,951,85-5,1%2-5,1%  #NUM!
Sheet1
Cell Formulas
RangeFormula
M5:M31M5=LEFT(F5,4)
N5:N31N5=RIGHT(F5,4)
O5:O31,U5:U31,R5:R31O5=(N5-M5)/M5
P5:P31P5=LEFT(G5,4)
Q5:Q31Q5=RIGHT(G5,4)
S5:S31S5=LEFT(H5,4)
T5:T31T5=RIGHT(H5,4)
V5:V31V5=IF(O5=W5,1,IF(R5=W5,"X",IF(U5=W5,2)))
W5:W31W5=MIN(O5,R5,U5)
X5:X31X5=IF(A5="","",IF(AND(A5>B5,V5=1),(N5-1)*1,IF(AND(A5<B5,V5=2),(T5-1)*1,IF(AND(A5=B5,V5="X"),(Q5-1)*1,IF(AND(A5>B5,V5="X"),-1,IF(AND(A5>B5,V5=2),-1,IF(AND(A5<B5,V5=1),-1,IF(AND(A5<B5,V5="X"),-1,IF(AND(A5=B5,V5=1),-1,IF(AND(A5=B5,V5=2),-1))))))))))
Y5:Y31Y5=IF(COUNTIFS(E$5:E5,E5,I$5:I5,I5)>1,"",IF(SUMPRODUCT(--(E$5:E$103=E5),--(I$5:I$103=I5),--($K$5:$K$103+$L$5:$L$103=AGGREGATE(15,6,($K$5:$K$103+$L$5:$L$103)/($E$5:$E$103=E5)/($I$5:$I$103=I5),1)))=1,X5,AGGREGATE(14,6,$X$5:$X$103/($E$5:$E$103=E5)/($I$5:$I$103=I5)/($K$5:$K$103+$L$5:$L$103=AGGREGATE(15,6,($K$5:$K$103+$L$5:$L$103)/($E$5:$E$103=E5)/($I$5:$I$103=I5),1)),1)))
Z5:Z31Z5=IF(COUNTIFS(E$5:E5,E5,I$5:I5,I5)>1,"",AGGREGATE(14,6,$X$5:$X$100/($E$5:$E$100=E5)/($I$5:$I$100=I5)/($K$5:$K$100+$L$5:$L$100=AGGREGATE(15,6,($K$5:$K$100+$L$5:$L$100)/($E$5:$E$100=E5)/($I$5:$I$100=I5),1)),1))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I:ICell ValueduplicatestextNO
E:ECell ValueduplicatestextNO
I27:I31Cell ValueduplicatestextNO
E27:E31Cell ValueduplicatestextNO
E5:E26Cell ValueduplicatestextNO
I4,I32:I1048576Cell ValueduplicatestextNO
E4,E32:E1048576Cell ValueduplicatestextNO
I32:I1048576,I4Cell ValueduplicatestextNO
E4Cell ValueduplicatestextNO
 
Upvote 0
The problem appears to be in your X5 formula. My formulas assumed that everything in the VS column would be numeric, otherwise the idea of "greater than" doesn't have much meaning. Your X5 formula is:

Rich (BB code):
=IF(A5="","",IF(AND(A5>B5,V5=1),(N5-1)*1,IF(AND(A5<B5,V5=2),(T5-1)*1,IF(AND(A5=B5,V5="X"),(Q5-1)*1,IF(AND(A5>B5,V5="X"),-1,IF(AND(A5>B5,V5=2),-1,IF(AND(A5<B5,V5=1),-1,IF(AND(A5<B5,V5="X"),-1,IF(AND(A5=B5,V5=1),-1,IF(AND(A5=B5,V5=2),-1))))))))))

The red part shows a case where it returns a null instead of a number. So my formula can't find a "greatest" value. Try changing that to

Rich (BB code):
IF(A5="",0,

or

Rich (BB code):
IF(A5="",-99

or something similar.
 
Upvote 0
The problem appears to be in your X5 formula. My formulas assumed that everything in the VS column would be numeric, otherwise the idea of "greater than" doesn't have much meaning. Your X5 formula is:

Rich (BB code):
=IF(A5="","",IF(AND(A5>B5,V5=1),(N5-1)*1,IF(AND(A5<B5,V5=2),(T5-1)*1,IF(AND(A5=B5,V5="X"),(Q5-1)*1,IF(AND(A5>B5,V5="X"),-1,IF(AND(A5>B5,V5=2),-1,IF(AND(A5<B5,V5=1),-1,IF(AND(A5<B5,V5="X"),-1,IF(AND(A5=B5,V5=1),-1,IF(AND(A5=B5,V5=2),-1))))))))))

The red part shows a case where it returns a null instead of a number. So my formula can't find a "greatest" value. Try changing that to

Rich (BB code):
IF(A5="",0,

or

Rich (BB code):
IF(A5="",-99

or something similar.
Thanks again for the alternative solution.
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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