?HowTo: Return Latest Date in One Field, Based on Matched Criteria in 2 Other Fields

Default300

Board Regular
Joined
Jul 13, 2009
Messages
83
Hi. Can you help me solve this puzzle? Hope so.
I've begun by showing the setup I have, but if you want to read the task and problem first, they're stated below.
Tables have been stripped down to the essential columns; and cell references and sheet names have been simplified.

SCENARIO / SETUP

Table 1 (DeviceDetails) (I'll call the worksheet DvcDtl for this example)

Table of Devices.

Each row / record refers to a single Device with a unique DeviceID, with various Details of that device listed in columns / fields.

There is exactly 1 row / record for each Device.


<tbody>
[TH="align: left"] State
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"] Existing
[/TH]
[TH="align: left"] Proposed / New
[/TH]

[TH="align: left"] Content
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"] Constant
[/TH]
[TH="align: left"] Formula
[/TH]

[TH="align: left"] DataType
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"] Integer
[/TH]
[TH="align: left"] Date
[/TH]

[TH="align: left"] Format
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"] 0000
[/TH]
[TH="align: left"] dd/mm/yyyy
[/TH]

[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]

[TH="align: left"]
[/TH]
[TH="align: left"][/TH]
[TH="align: left"] A
[/TH]
[TH="align: left"] B
[/TH]

[TH="align: left"] Header
[/TH]
[TH="align: left"] 1
[/TH]
[TH="align: left"] DeviceID
[/TH]
[TH="align: left"] LatestPrintDate
[/TH]

[TH="align: left"] Data
[/TH]
[TH="align: left"] 2
[/TH]
[TH="align: right"] 0111
[/TH]
[TH="align: right"] 31/12/2001
[/TH]

[TH="align: left"] Data
[/TH]
[TH="align: left"] 3
[/TH]
[TH="align: right"] 0222
[/TH]
[TH="align: right"] 29/10/2001
[/TH]

[TH="align: left"] Data
[/TH]
[TH="align: left"] 4
[/TH]
[TH="align: right"] 0333
[/TH]
[TH="align: right"] 30/11/2001
[/TH]

</tbody>


Table 2 (ServiceRecords) (I'll call the worksheet SrvRcd for this example)

Table of Service Records for devices.

Each row is a single Service Event with a unique ServiceEventID, and concerns a single device identified by its unique DeviceID.

There is exactly 1 row / record for each ServiceEvent.

But there may be 0, 1 or multiple ServiceEvents for each Device.

If it were a relational database, then the relationship between the DeviceDetails table and the ServiceRecords table (for the DeviceID field) would be referred to as "one-to-many".

[TABLE="width: 500"]
<tbody>[TR]
[TH="align: left"]State
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]Existing
[/TH]
[TH="align: left"]Existing
[/TH]
[TH="align: left"]Existing
[/TH]
[TH="align: left"]Existing
[/TH]
[TH="align: left"]Proposed / New
[/TH]
[/TR]
[TR]
[TH="align: left"]Content
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]Constant
[/TH]
[TH="align: left"]Constant
[/TH]
[TH="align: left"]Constant
[/TH]
[TH="align: left"]Constant
[/TH]
[TH="align: left"]Formula
[/TH]
[/TR]
[TR]
[TH="align: left"]DataType
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]Integer
[/TH]
[TH="align: left"]Integer
[/TH]
[TH="align: left"]Text
[/TH]
[TH="align: left"]Date
[/TH]
[TH="align: left"]Date
[/TH]
[/TR]
[TR]
[TH="align: left"]Format
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]0000
[/TH]
[TH="align: left"]0000
[/TH]
[TH="align: left"]General
[/TH]
[TH="align: left"]dd/mm/yyyy
[/TH]
[TH="align: left"]dd/mm/yyyy
[/TH]
[/TR]
[TR]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[/TR]
[TR]
[TH="align: left"]
[/TH]
[TH="align: left"]
[/TH]
[TH="align: left"]A
[/TH]
[TH="align: left"]B
[/TH]
[TH="align: left"]C
[/TH]
[TH="align: left"]D
[/TH]
[TH="align: left"]E
[/TH]
[/TR]
[TR]
[TH="align: left"]Header
[/TH]
[TH="align: left"]1
[/TH]
[TH="align: left"]ServiceEventID
[/TH]
[TH="align: left"]DeviceID
[/TH]
[TH="align: left"]ServiceDocType
[/TH]
[TH="align: left"]ServiceDocDate
[/TH]
[TH="align: left"]LatestPrintDate
[/TH]
[/TR]
[TR]
[TH="align: left"]Data
[/TH]
[TH="align: left"]2
[/TH]
[TH="align: right"]0995
[/TH]
[TH="align: right"]0111
[/TH]
[TH="align: left"]Printed
[/TH]
[TH="align: right"]29/10/2001
[/TH]
[TH="align: right"]31/12/2001
[/TH]
[/TR]
[TR]
[TH="align: left"]Data
[/TH]
[TH="align: left"]3
[/TH]
[TH="align: right"]0996
[/TH]
[TH="align: right"]0333
[/TH]
[TH="align: left"]Written
[/TH]
[TH="align: right"]29/10/2001
[/TH]
[TH="align: right"]30/11/2001
[/TH]
[/TR]
[TR]
[TH="align: left"]Data
[/TH]
[TH="align: left"]4
[/TH]
[TH="align: right"]0997
[/TH]
[TH="align: right"]0222
[/TH]
[TH="align: left"]Printed
[/TH]
[TH="align: right"]29/10/2001
[/TH]
[TH="align: right"]29/10/2001
[/TH]
[/TR]
[TR]
[TH="align: left"]Data
[/TH]
[TH="align: left"]5
[/TH]
[TH="align: right"]0998
[/TH]
[TH="align: right"]0111
[/TH]
[TH="align: left"]Written
[/TH]
[TH="align: right"]30/11/2001
[/TH]
[TH="align: right"]31/12/2001
[/TH]
[/TR]
[TR]
[TH="align: left"]Data
[/TH]
[TH="align: left"]6
[/TH]
[TH="align: right"]0999
[/TH]
[TH="align: right"]0333
[/TH]
[TH="align: left"]Printed
[/TH]
[TH="align: right"]30/11/2001
[/TH]
[TH="align: right"]30/11/2001
[/TH]
[/TR]
[TR]
[TH="align: left"]Data
[/TH]
[TH="align: left"]7
[/TH]
[TH="align: right"]1000
[/TH]
[TH="align: right"]0111
[/TH]
[TH="align: left"]Printed
[/TH]
[TH="align: right"]31/12/2001
[/TH]
[TH="align: right"]31/12/2001
[/TH]
[/TR]
</tbody>[/TABLE]


TASK

I want to know what was the most recent date on which a service record was printed (as opposed to written), for each device.

What formula should I use in LatestPrintDate column, to return the date shown?

NB: The LatestPrintDate column can be in either Table, though I think it makes more sense in the DeviceDetails table, where the calculation would be performed once for each device.

It's possible to introduce one or more new columns in either table if required. In fact I'd prefer to have more columns than a very convoluted nested formula.

I'd prefer not to use an array formula. If I must, then I'd prefer one contained within a single cell rather than stretched across a full column.

I'd like to use SUMPRODUCT if possible, as I find that syntax easy to read and edit.
Perhaps MAX, LARGE and/or SUBTOTAL has a part to play (to return the latest date).

If using LARGE, I'd prefer to use a constant to define parameter "K", rather than to use ROW().

If lookups are required, then I prefer INDEX + MATCH rather than VLOOKUP etc.


ATTEMPTED SOLUTION

If inserting proposed new column into the DeviceDetails Table (NOT ServiceRecords Table), then perhaps something similar to this...

=SUMPRODUCT(('SerRec'!$A$2:$A$7='DvcDtl'!$A2)*('SerRec'!$C$2:$C$7="Printed")*(MAX('SerRec'!$D$2:$D$7)))


PROBLEM

Date returned by above formula is wrong.

It is returning the same maximum date for all devices (not the specific device referenced).

It then multiplies this date by the number of instances that the specific device has had a service record printed.

Not what I want, obviously!


Any ideas? :confused:

Thanks in advance. ;-)

(BTW the table reformatted the alignment of all cells to centered, despite careful setup)
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try something like this....

=MAX(IF((SerRec!$B$2:$B$7=DvcDtl!$A2)*(SerRec!$C$2:$C$7="Printed"), SerRec!$D$2:$D$7))

This is an array formula confirmed with Ctrl+Shift+Enter
 
Upvote 0
@ AlphaFrog

Thanks. :wink:

Regarding the array formula...

It's the type where you "array-enter" the formula in a single cell and then fill or copy paste it down the whole column, right?

It's NOT the type where you fill or copy paste the "non array-entered" formula down the whole column; select all those cells; F2; and array-enter it, creating a single array of all the formulae cells in the column, is it?

I'm trying to avoid the latter ones especially, as they make life hard when trying to extend tables.

I don't know what impact array formulae have on calculation speed versus other solutions (if they exist).

I presume you would have offered a non-array equivalent if there was one that you knew of.

Thanks for your suggestion. I'll give it a try.

Cheers.
 
Last edited:
Upvote 0
@ AlphaFrog

I gave that a go, and it seems to work, at least on initial testing.

Thanks for your advice and your time. :wink:

If anyone has any other suggestions I'd still be interested to hear them.

Or if anyone has an opinion on my concern re array formulae and calculation time (or links to articles debating the subject for me to read).

Cheers.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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