Earliest date in fields of the same record

oni1983

New Member
Joined
Jul 9, 2015
Messages
25
I have a query in which I am storing the details of trainees and their courses (including start and end dates). The trainee details and the course details belong to two different tables. Each trainee is entitled to a maximum of 10 courses.

I am now building a 'training history' of each trainee and I need to know when the trainee started training i.e. the earliest Start Date when the trainee started his first course.

I need to work this out via query (not a report) since I need to present the date in sheet format.

The query I have created consists of the details of the trainee and 10 columns, each showing the start date of that particular course. How can i compare the columns so that:

1. Either the dates are listed earliest first and latest at the end
2. The earliest date is shown and all the other dates are replaced with a blank cell.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
It is always best to show examples of what your data looks like, and what your want your expected results to look at.

It sounds like you will probably need to incorporate an Aggregate (Total) Query, where you include which fields you want to Group By, and then they field you want the earliest date on (you will use the MIN function here).

See here: https://support.office.com/en-us/ar...-a-query-b84cdfd8-07ba-49a7-b067-e1024ccfcca8
You would just choose to use the MIN function in place of the COUNT function in their example.
 
Upvote 0
This is what my data looks like:

Participant ID NumberParticipant NameParticipant SurnameCourse 1 Start DateCourse 2 Start DateCourse 3 Start DateCourse 4 Start DateCourse 5 Start DateCourse 6 Start DateCourse 7 Start DateCourse 8 Start DateCourse 9 Start DateCourse 10 Start Date
25632MAaaaBbbb









480356MSamuelBarbara25/02/201702/03/201703/03/2017






510183MCharmaineBarbara15/03/201702/03/201702/02/201726/03/2017

25/03/2017
02/03/2017

<caption> LMP - First Training Start Date </caption><thead>
</thead><tbody>
</tbody><tfoot></tfoot>

What I would like is to create a query in which the data shown is like the following (basically I am now being shown only the earliest date for each record):

Participant ID NumberParticipant NameParticipant SurnameCourse Earliest Date
25632MAaaaBbbb
480356MSamuelBarbara25/02/2017
510183MCharmaineBarbara02/02/2017

<caption> LMP - First Training Start Date </caption><thead>
</thead><tbody>
</tbody><tfoot></tfoot>

I have tried the Totals Query you suggested but unfortunately it is not working. The query is returning basically the same data without any filtering whatsoever.
 
Upvote 0
One big issue is that your data table is not normalized!
You should never have similar repeating data going across your table like that. It makes the data very difficult to work with (as you are currently experiencing).

You should have at least two tables with the following fields.

Participant_Table
Participant_ID (primary key)
Participant_Name
Participant_Surname

Participant_Course_Table
Participant_Course_ID (primary key - can use Autonumber if you like)
Participant_ID (from Participant_Table)
Course_Number
Course_Start_Date

Participant_Course_IDParticipant_IDCourse_NumberCourse_Date
1480356M125/02/2017
2480356M202/03/2017
3480356M303/03/2017
4510183M115/03/2017
5510183M202/03/2017
6510183M302/02/2017
7510183M426/03/2017
8510183M725/03/2017
9510183M902/03/2017

<tbody>
</tbody>

So then the SQL code for the Aggregate Query would just look like:
Code:
SELECT Participant_Course_Table.Participant_ID, Min(Participant_Course_Table.Course_Date) AS MinOfCourse_Date
FROM Participant_Course_Table
GROUP BY Participant_Course_Table.Participant_ID;
And it would return data looking like:
Participant_IDMinOfCourse_Date
480356M25/02/2017
510183M02/02/2017

<tbody>
</tbody>

To get it to return data in the manner that you like, you would save this Aggregate Query. and then do a Left Join from your participant table to this query, i.e.
Code:
SELECT Participant_Table.Participant_ID, Participant_Table.Participant_Name, Participant_Table.Participant_Surname, Min_Course_Date_Query.MinOfCourse_Date
FROM Participant_Table 
LEFT JOIN Min_Course_Date_Query 
ON Participant_Table.Participant_ID = Min_Course_Date_Query.Participant_ID;
and the results would look like:
Participant_IDParticipant_NameParticipant_SurnameMinOfCourse_Date
25632MAaaaBbbb
480356MSamuelBarbara25/02/2017
510183MCharmaineBarbara02/02/2017

<tbody>
</tbody>
 
Last edited:
Upvote 0
Wow, thanks for the detailed reply. I will change the way the data is presented in my table as you suggested and see how that works out.

Thanks again.
 
Upvote 0
It worked!!! Thanks for your help!!

But I have a small concern, I need to make sure that when the data is being inputted, the course number for the same participant is not the same i.e. there must not be two courses with course number 1 for the same participant but there can be more courses with course number 1 for several participant.

How can I do that?
 
Upvote 0

Forum statistics

Threads
1,221,709
Messages
6,161,442
Members
451,705
Latest member
Priti_190

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