Find consecutive records

millerlite2ky

Board Regular
Joined
Oct 25, 2002
Messages
87
I have a database consisting of race results. For the recordbook, without having to manually do this, I'd like to find out which driver has the record for most consecutive starts, wins, etc. Is there a way to do this for a report or a form.

Scott
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Scott
I've had a play around with some sample data and I think this can be done but I need a little more information. I had a look at your previous posts but thought it might be safer to ask straight out : what are your data structures? In particular, how have you set up your driver, race event and race result tables?
Andrew.
 
Upvote 0
driver table is set up as Driver ID and Driver.
Event table is set up with about 30 columns/fields of data including Driver ID.
Results table is set up with about 20 columns/fields of data also including Driver ID.
I'm basically wanting to find how many consecutive races a driver has driven in by using a query of the tables (Driver & Results).
The Results table is related to the Drivers table via the Driver ID field, and the Results table consists of a numerical field which includes the Event ID, which is related to the Events table.

I'm not sure if this will help, but I appreciate your input.

Scott
 
Upvote 0
Hi Scott

Apologies in advance for the long answer but this was a lot harder than I had imagined it would be. I've managed to get it to work with very similar tables using test data - but to get it to work I had to use an autonumber for the driver id.

A couple of questions : is your driver id an autonumber? Does the event table include the event date? ( <- Silly question I know but I had to ask it...) Also, is the driver's start in a race recorded by way of being present in the results table? Or something else? ....

Event table is set up with about 30 columns/fields of data including Driver ID.

The bit above has me confused - is the driver id recorded in the event table? I wouldn't have thought that was necessary given the drivers and events are "brought together" in the results table.

If a driver starts a race but DNF's - how is this recorded? I used yes/no variables in the results table to indicate if a driver started and / or finished a race, and another variable to record the drivers final position.

Anyway, questions aside, the way I got it to work was to create a select query based on the driver table and event table (with no links whatsoever), added the driver id, name, event id, description, date and a "sequence" field (sort ascending), as follows :

Sequence: ( [Driver_ID] * 1000000) + Format( Year( [Event_Date]), "0000" ) & Format( Month( [Event_Date] ),"00" ) & Format( Day( [Event_Date] ),"00" )

Save the query.

This "sequence" is used to give you the sort order of the records for determining consecutive starts, wins etc. later on. We need this to create a value that we can use to rank the records that will provide an incremental number - which we need when comparing one record to another in a query to determine whether something is consecutive or not.

This query creates a record for every driver for every race - this is necessary to include the races in which a driver did not start.

Please note that I have assumed there won't be more than 1m events in making a unique value - you can change the 1m bit to more if you want.

I then created another select query, based on the first query included the driver id, name, event id, description, date and a new field called "ranking", see below :

Ranking: (Select Count(*) from Query1 where [Sequence] < [Query1Alias].[Sequence] ; )+1 {I discussed the table alias in a previous post but it is necessary for the "ranking" - use your actual query & variable names, ask if you're not sure}

Save the query.

I then created a 3rd query, based on the 2nd query and the results table, linked on the event id and driver id (go into the link properties and force both links pick up all records from the query and just the matching records from the table), add the ranking (sort ascending), driver id, name, event id, description, date, "start", "finish" and "place" variables (see below - slight name changes from the actual variable names in the results table), a "samedriver" variable (see below), and a "starts" or "wins" variable (see below).

The "start" & "finish" variables came from the results table (I used yes/no indicators in the results table to indicate whether a driver had started and / or finished the race) and the "place" variable also came from the results table (I used a numerical value to indicate the place in the race, with 1 = 1st, 2 = 2nd and so on and 0 = DNF and / or DNS).

In the query, "start", "finish" and "place" were coded like this :

Start: IIf( [Started] = Yes, 1, 0 ) {NB the actual variable name in the results table was "started"}
Finish: IIf( [Finished] = Yes, 1, 0 ) {NB I actually used "finished" in the results table}
Place: IIf( IsNull( [Position] ), 0, [Position] ) {NB I used "position" in the results table}

The details for the "samedriver" is :

SameDriver: IIf([Query2].[Driver_ID] = (DLookUp( "[Driver_ID]", "Query2","Ranking =" & [Ranking]-1)),1,0) {use your real query 2 name}

In the same query, you can calculate the consecutive starts with this :

Consec_Starts: IIf( [Start] =0, 0, IIf( [SameDriver]=0, 1, [Start] + (DLookUp( "[Consec_Starts]", "[Query3]", "Ranking = " & [Ranking]-1)))) {use your real query 3 name}

Or consecutive wins with this :

Consec_Wins: IIf([Start]=0, 0, IIf([SameDriver]=0, IIf([Place]=1, 1, 0 ) , IIf( [Place] <> 1, 0, [Place] + (DLookUp("[Consec_Wins]", "[Query3]", "Ranking = " & [Ranking]-1 ))))) {use your real query 3 name}

Save the query.

...and so on for consecutive finishes, DNF's, 2nds - whatever you want. Please note that the query really slows down with lots of data and the more fields you add the slower it gets, so you might want to do wins in one query and starts in another and so forth. I'm using a P4 and it was noticeably slow with only 20 race result records.

To finish it off, I created a 4th query based on the 3rd query, added the "starts" and "wins" variables, view totals, set both totals to "Max".

Save the query.

Lastly, to retrieve just the "max" records, I created a 5th query based on the 3rd and 4th queries, linked the "wins" in query 3 with "maxofwins" in query 4 (or "starts" & "maxofstarts") and then included all records from query 3.

Save and run and hey presto, your max consecutive wins (or starts) with the driver and event in which it happened.

Someone smarter than I may be able to code all of this in VB to make it quicker and more efficient - as I mentioned earlier my query was very slow even when using a P4 PC.

HTH, Andrew. :)
 
Upvote 0
Thanks for the reply. I'll give it a try! Now to answer a few of your questions:

My DriverID in my Drivers table is set to AutoNumber.
The Event date is included in my Event table.
Also included in my Events table is a field for the Pole Position winner. This field is related to the Drivers table via the Driver ID. This way, I cannot input a name which isn't included in the Drivers table.

My fields for Events table include:
EventsID, Year, Date, Race #, Track, Location, Config, Type, Length, Pole Winner, Pole Make, Pole Speed, Outside Pole, Race Winner, Race Make, Race Speed, Car #, Owner, Cautions, Caution Laps, Leaders, Lead Changes, Race Purse, Attendance, # of Cars in race.

My fields for Results table include:
ResultsID, EventID, Year, Date, Race #, Track, Finish, Start, Car #, Driver, Car Make, Pts, Led Pts, Earnings, Laps, Laps Led, Miles Led, Miles, Sponsor, Owner, Performance Pts, Fantasy Pts.

My fields for Drivers table include:
DriverID, Driver

My fields for Owner table include:
OwnerID, Owner

My fields for Tracks table include:
TrackID, Track, Location

My fields for Car Makes table include:
CarMakeID, Make

My Events & Results include some of the same info, I know, because of different queries I was working with. I'm also using Excel for most of the calculations and then pasting the race results to Access, until I can figure out how to do it within Access.

Hope this will help:

Scott
 
Upvote 0
I forgot to tell you also:

I have a field in the Results table called Status.
Anything in this field which doesn't say "Running", is considered a DNF (Crash, Suspension, Transmission, etc).
This is how I determine RAF's (Running at Finish) and DNF's, by subtracting from total races ran.

Scott
 
Upvote 0
Hi Scott, thanks for all of the details. Having skim read your reply I think my solution will still work but you will have slightly differing variable names.

A couple of points to note : when you create the list of "driver / events" when doing this bit :

the way I got it to work was to create a select query based on the driver table and event table (with no links whatsoever), added the driver id, name, event id, description, date and a "sequence" field (sort ascending)

...remember to delete the existing link between the driver and event tables. The other reason I used the "sequence" was so that you could enter the events out of chronological order and it wouldn't matter.

Also, I take it that a driver id being recorded in the results table indicates the driver has started (excellent) and you mentioned the "status" variable is the finish indicator. So in place of my "started" variable, you could use the "result id" (or another field) instead and in place of my "finished" variable, you can use your "status" variable (although modifying the queries slightly to recognise "Running" rather than my "yes" etc). I'm referring to this bit :

Start: IIf( [Started] = Yes, 1, 0 ) {NB the actual variable name in the results table was "started"}
Finish: IIf( [Finished] = Yes, 1, 0 ) {NB I actually used "finished" in the results table}

Let us know how you get on.

BTW, which series are you tracking? NASCAR? CART? Both? Or something else?

HTH, Andrew. :)

P.S. Go Scott Dixon! :cool:
 
Upvote 0
Thanks for all the help......I'm a huge NASCAR fan & am working with the race results for my fantasy league, etc.

I follow the Penske cars, somewhat, within the IRL. I've been to several IRL races the past couple of years.

I'll let you know how this works out.

Scott
 
Upvote 0
I have a question. In step two (Query2).......you mention the QueryAlias.
Step two I have Query1 shown in the design window....Do I select Query1...View...Properties.....Alias......Query1Alias???

When I did, the Query1 in design window changed to Query1Alias.
Is this right?

Scott
 
Upvote 0
Also, are you talking about deleting the existing relationship between my Drivers table and Events table in the Relationship window?

Scott
 
Upvote 0

Forum statistics

Threads
1,221,825
Messages
6,162,166
Members
451,750
Latest member
dofrancis

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