Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Expanding date fields

One of my co workers posted a post earlier concerning something similiar and though the theory worked it will not work for what we need it for.

Here is the situation:

We have two tables:

The First Contains Dispatch Info with a new entry put in every time the driver switches loads:

TripNoTrailerNoDispatch DateDriverCodeSkirts
51455458711/1/2009DIRKA0
51465454711/5/2009DIRKA0
51568457811/9/2009DIRKA1
58465457811/14/2009DIRKA0
54686468511/10/2009MARKC0
51548457811/15/2009MARKC1


The 2nd contains MPG information Date Ranges Differ from table above the MPG query is trigger manually or by a new dispatch:

StartDateEndDateDriverCodeMPG
11/1/200911/3/2009DIRKA12.5
11/3/200911/5/2009DIRKA11.5
11/5/200911/9/2009DIRKA14.5
11/9/200911/14/2009DIRKA16.5
11/14/200911/16/2009DIRKA10.3
11/10/200911/12/2009MARKC11.5
11/12/200911/15/2009MARKC13.2
11/15/200911/16/2009MARKC17.2


My idea is converting the first table into something like this:

TripNoTrailerNoDispatch DateDriverCode
51455458711/1/2009DIRKA
51455458711/2/2009DIRKA
51455458711/3/2009DIRKA
51455458711/4/2009DIRKA
51465454711/5/2009DIRKA
51465454711/6/2009DIRKA
51465454711/7/2009DIRKA
51465454711/8/2009DIRKA
51568456811/9/2009DIRKA
51568456811/10/2009DIRKA
51568456811/11/2009DIRKA
51568456811/12/2009DIRKA
51568456811/13/2009DIRKA
58465456811/14/2009DIRKA
58465456811/15/2009DIRKA
58465456811/16/2009DIRKA
54686468511/10/2009MARKC
54686468511/11/2009MARKC
54686468511/12/2009MARKC
54686468511/13/2009MARKC
54686468511/14/2009MARKC
51548456811/15/2009MARKC
51548456811/16/2009MARKC


Thus giving each date a full row of info. Then making a "=Date&DriverCode" key.

Then do the same with the MPG Table and make another "Date&DriverCode" Key

We do not know how to do this expansion inside the code. I have wondered if an autogenerate macro would do it. AutoGenerate(date) until a new record #?

I dont know just through things out there.

The end goal is to be able to track the MPG for each driver each day and compare those days he tows trailers with "skirts" to the days he tows other trailers.

Any ideas are welcome.

Please Help.

1 Reply
johnw
Champion III
Champion III

If this is long haul trucking data, having multiple dispatches in a single day seems like an inevitability. When that does happen, merely storing dates is ambiguous. You say you trigger a new MPG record for each dispatch. So now we have multiple MPG records and multiple dispatches, all on the same day, with nothing to distinguish between them. Multiple dispatches in a single day is also a problem for your intended goal of one record per day. You would need multiple records per day.

The simple solution to the ambiguity problem is to store timestamps, not merely dates. However, it will not be possible to create a separate record for every millisecond in the day. Perhaps it is impossible to have more than one dispatch in an hour, and you could generate hourly records, but that's still a whole lot of redundant data.

So I think we need to get back to this:

The end goal is to be able to track the MPG for each driver each day and compare those days he tows trailers with "skirts" to the days he tows other trailers.


See the attached for a way to turn your raw data into a single combined table with records that support this analysis. If I've misunderstood the requirement, please clarify.

I should also note that your example data is insufficient to actually calculate the average MPG. I weighted it by days driven, since that seemed to be what you were after, but this is incorrect. The correct way to handle it is to store both the miles driven and the gallons of gasoline used, then simply sum(Miles)/sum(Gallons). Is this information available?

Mind you, I really need to get back to my own work, so I'm not sure when or if I might be able to get back to this. Ah, well. Hopefully something I've said was helpful.