Logic Question - Complicated Criteria

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a database that maintains information of a customers rental of a facility.
Normally, the customer rents "room A" for a large block of time, say 5:30 PM - 8:30PM, for which their is one simple record for this rental.
On occassion though, the customer will rent that same block of time between two or more rentals, say 5:30-6:30PM and 6:30PM - 8:30PM. Two separate records share the same information (contract number, location and activity) with the exception of the start/end times.

With the help of individuals here at Mr. Excel, using a complex combination of named ranges, advanced filters, and pivottables I have managed to find and merge the duplicate pairs so that the two records become one with the appropriate start and end times.

But I've ran into a scenario where this is inappropriate. There are instances where there are two records, both with the same contract number, location and activity, and both with different times. Normally, the code would merge the two with the lowest of the two times being the start time, and the highest of the two being the end time. This is quite appropriate when the two rentals are back to back. However, this would be inappropriate if, although information was the same, they were not back to back. So, two identical records, with one being from 5:30 - 8:30 and a second from 9:00 - 10:30 must not be merged, but be treated at unique.

So my database (sorted in descending order by facility) has three flagged columns (NOP)for use in filtering.

Column N is a concatenation of contract number, facility and activity.
Column O {=COUNTIF(N:N,$N8)>1} returns true if an identical value is found in column N, false if it is unique. All those returning true will have one or more identical records according to the value in column N
Column P {=IF($N8=$N7,"DUP","")} identifies the duplicate(s) within any group of matching records.

Before any filtering is done, a pivvotable is refreshed in which the the count of identical records (column N) is calculated, in addition to the min start time of each group of identical records. This pivottable forms the seach range for the vlookup formula which changes the start time of the merged records.

Advanced filters are applied to filter all "True" values in O, and "DUP" in P.

Those records filtered "DUP" will be deleted from the database, leaving only one unique record from each group. That rental number is crossreferenced withthe pivottable and the min value for it's corresponding start time is substituted into the appropriate cell in the database.

My question ... the use of the formula in column P, used to establish which rows get deleted, isn't accurate. I need to somehow assign "DUP" only to those identical records (column N) in which the start time of the second record is 30 minutes or more than the end time of the first? Those that have a gap of 30 minutes or more will be unique, not labelled "DUP" and thus will not be deleted.

See sample below ...

Book1
ABCDEFGHIJKL
31508163:00PM5:00PM50816NorthfieldParkFieldTRUEDUPRecords1and2,althoughidentical(E)are30minutesapart,
42508165:30PM8:30PM50816NorthfieldParkFieldTRUEunlikebeingbacktobackliketheothers.
53904925:00PM6:30PM90492RIMParkOutdoorFacilitiesBallDiamond#1TRUEDUPDeleted
64904926:30PM8:00PM90492RIMParkOutdoorFacilitiesBallDiamond#1TRUEDUPDeleted
75904928:00PM9:30PM90492RIMParkOutdoorFacilitiesBallDiamond#1TRUEDUPDeleted
86904929:30PM11:00PM90492RIMParkOutdoorFacilitiesBallDiamond#1TRUE904925:00PM11:00PM90492RIMParkOutdoorFacilitiesBallDiamond#2
97904925:00PM6:30PM90492RIMParkOutdoorFacilitiesBallDiamond#2TRUEDUPDeleted
108904926:30PM8:00PM90492RIMParkOutdoorFacilitiesBallDiamond#2TRUEDUPDeleted
119904928:00PM9:30PM90492RIMParkOutdoorFacilitiesBallDiamond#2TRUEDUPDeleted
1210904929:30PM11:00PM90492RIMParkOutdoorFacilitiesBallDiamond#2TRUE904925:00PM11:00PM90492RIMParkOutdoorFacilitiesBallDiamond#2
1311904925:00PM6:30PM90492RIMParkOutdoorFacilitiesBallDiamond#4TRUEDUPDeleted
1412904926:30PM8:00PM90492RIMParkOutdoorFacilitiesBallDiamond#4TRUE904926:30PM8:00PM90492RIMParkOutdoorFacilitiesBallDiamond#4
1517910286:30PM7:15PM91028RIMParkOutdoorFacilitiesBeachVolleyballCourt1TRUEDUPDeleted
1618910287:15PM8:00PM91028RIMParkOutdoorFacilitiesBeachVolleyballCourt1TRUE910286:30PM8:00PM91028RIMParkOutdoorFacilitiesBeachVolleyballCourt1
Sheet1


Jenn

One filter is applied that will isolate all records having more than one matching (rental number+facility+activity) concatenation. If there is more than onee matching instance, this column is "TRUE", and the filter will filter all records not true.

A third column looks at the f
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
So, if I see it correctly, you have the starting and ending times in L and M.

Column P {=IF(AND($N8=$N7,$L8-$M7<0.020834),"DUP","")}

The 0.020834 is 30 min.
 
Upvote 0
Thank you LxQ,

I'll have to wait until tomorrow to try it out and let you know the result. The times for comparison reasons are actually in columns C and D. I'll make the changes to the formula!

Jenn
 
Upvote 0
Hi everyone,

LxQ, I've adapted your suggested formula ...
Rich (BB code):
=IF(AND($N8=$N7,$C8-$D7<=0.020833),"DUP","")
.
and it works great!!! Thank you LxQ!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,560
Messages
6,160,493
Members
451,653
Latest member
agata

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