Sometimes time intervals are not stored explicitly with a beginning and an end. Instead they are implied by only one field – the change timestamp.
It could be as in the table below where you have currency rates for multiple currencies. Each currency rate change is on its own row; each with a new conversion rate. Also, the table contains rows with empty dates corresponding to the initial conversion rate, before the first change was made.
This table defines a set of non-overlapping intervals, where the begin data is called “Change Date” and the end date is defined by the beginning of the following interval. But since the end date isn’t explicitly stored in a column of its own, we need to create such a column, so that the new table will become a list of intervals.
Do the following:
- Create a file called Rates.xlsx containing the table shown above and store it ready for loading.
- Determine which time range you want to work with. The beginning of the range must be before the first date in the data and the end of the range must be after the last.
- Load the source data, but change empty dates to the beginning of the range defined in the previous bullet. The change date should be loaded as “From Date”.
- Sort the table first according to Currency, then according to the “From Date” descending so that you have the latest dates on top.
- Run a second pass through data where you calculate the “To Date”. If the current record has a different currency from the previous record, then it is the first record of a new currency (but its last interval), so you should use the end of the range defined in step 1. If it is the same Currency, you should take the “From Date” from the previous record, subtract a small amount of time, and use this value as “To Date” in the current record.
Make sure that the dates in the Change Date column are in the same format as the local date format.
The script listed below will update the source table in the following manner:
The QlikView script looks like this:
When this script is run, you will have a table listing the intervals correctly.
This table can subsequently be used in a comparison with an existing date using the Intervalmatch methods.