How to use countifs to return a max date from a list of dates meeting a certain critera?

Captain McFunk

New Member
Joined
Dec 12, 2016
Messages
7
Hey all, I had this answered last week that I could reference back to but it appears it was wiped out wit the db attack, so i'm posting again, i apologize for having to have it answered twice!

I have a list of patients that have multiple orders listed by date. I'm trying to find what is the most recent order date and corresponding row data for every customer id#. My table looks a little like this:

CustomerIDOrderDate
1234510/25/16
1234511/25/16
1234512/25/16
678919/25/16
6789110/25/16
6789111/25/16
6789112/25/16

<tbody>
</tbody>



I'm needing to be able to identify and filter to show just the rows for each customerid that have the most recent order date. I remember the solution having something to do with a countifs statement, but i tried a couple of times and couldn't get there. I would greatly appreciate some help!!!
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I wouldn't bother with a formula (unless for some other reason you want to). Sort the "OrderDate" column by most Newest to Oldest and then select the entire table and delete duplicate values based on column "CustomerID". Excel will delete duplicates starting from the bottom, thus, the only remaining value for each customerID is going to be the most recent.
 
Last edited:
Upvote 0
I wouldn't bother with a formula (unless for some other reason you want to). Sort the "OrderDate" column by most Newest to Oldest and then select the entire table and delete duplicate values based on column "CustomerID". Excel will delete duplicates starting from the bottom, thus, the only remaining value for each customerID is going to be the most recent.

Okay, I realized a slight issue when trying this, there is a piece of info i left out, my apologies! Each sales order has an item on it -- There could be a patient that receives 3 items on the same date -- They each have their own separate row -- I need to be able to see all 3 rows for that date for that patient, if that makes sense? I guess the table is more like:

CustomerIDOrderDateItemID
1234510/25/16Item1
1234511/25/16Item1
1234512/25/16Item1
678919/25/16Item3
6789110/25/16Item3
6789111/25/16Item3
6789111/25/16Item7

<tbody>
</tbody>


For this example, i need a formula that would return me this info:
CustomerIDOrderDateItemID
1234512/25/16Item1
6789111/25/16Item3
6789111/25/16Item7

<tbody>
</tbody>
 
Upvote 0
Very easy with a formula, especially if you don't want to delete records! C1 contains the customer ID you want to query:

=MAX(IF(A2:A8=C1,B2:B8))

confirmed by pressing CTRL+SHIFT+ENTER (not just ENTER) which will automatically insert curly brackets {} around the formula (don't try to type these yourself - it won't work).

EDIT: Just read your latest addition - now it is a completely different query!!! :cool:
 
Last edited:
Upvote 0
maybe something where, instead of deleting all duplicates, it would return all rows associated with the "newest" orderdate for each customerID if that makes sense?
 
Upvote 0
haha, all good, I just tried this, and this did give me the most recent order date for a given customerid, but just put it in a column I selected for ALL rows for a given patient ID. Thank you for helping though, looking forward to your next option!
 
Upvote 0
Here is the actual date with some edits made for HIPAA reasons....

Patient IDPatient Last NamePatient First NameSales Order Detail Item NameSales Order Detail QtyDelivery Actual date
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE111/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY111/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA211/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE110/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY110/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA210/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE19/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY19/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA29/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE18/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY18/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA28/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE17/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY17/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA27/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE16/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY16/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA26/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE15/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY15/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA25/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE14/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY14/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA24/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE13/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY13/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA23/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE12/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY12/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA22/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - CHOCOLATE11/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - STRAWBERRY11/17/2016
10228LastNameFirstNameBOOST KIDS ESSENTIALS - VANILLA21/17/2016

<tbody>
</tbody>
 
Upvote 0
In this scenario, i'd want it to look by patient id, and for all instances of each patient ID in a list of over 2,000 items, return all rows associated with the newest date, so in the above, it would look for the first patient id, 10228, and show me JUST the lines associated with the most recent date of 11/17/2016. How could I go about that? I'm pretty sure it's a countifs statement...
 
Upvote 0
in this scenario, i'd want it to look by patient id, and for all instances of each patient id in a list of over 2,000 items, return all rows associated with the newest date, so in the above, it would look for the first patient id, 10228, and show me just the lines associated with the most recent date of 11/17/2016. How could i go about that? I'm pretty sure it's a countifs statement...


tttop
 
Upvote 0
It's been just half an hour since you updated the thread - patience, please! Please remember that we are all helping here voluntarily and in our free time!!!

You are going to need an INDEX Match array formula to do what you want. I have to go out now, but if nobody has answered by the time I get back, then I shall propose a solution.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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