What price did you sell that product at on 14 March? The question sounds trivial. It is not. If your price list changed four times that year and your data model only stores today's price, your margin report has been lying for months and nobody has noticed. QlikSense IntervalMatch solves exactly that problem: it connects a discrete data point, a sales date, a sensor reading or a shift hour, with the interval that was in force at that moment. It is one of the least used functions in the load script language and, at the same time, one of the few that changes the result of an entire income statement.

The question your model cannot answer
It goes like this. The ERP delivers sales with product, quantity and date. The price list arrives separately, with validity ranges: from 1 January to 28 February, one price; from 1 March onwards, another. Two tables that share no key able to join them correctly.
The easy way out is a Join on product. It works, in the sense that it throws no error. It also multiplies every sale by every historical price of the product, and suddenly you have three times more rows than you should. The even easier way out is to use only the current price, which restates the whole historical margin at today's prices. That report looks flawless.
Industry figures back the diagnosis. More than 78% of global enterprises already run at least one BI or analytics platform, and 84% of executives consider analytics critical to their digital roadmap. Yet in the dbt Labs 2025 survey, 56% of practitioners pointed to poor data quality as their most frequent obstacle. Plenty of platform, little model.
What QlikSense IntervalMatch actually does
The prefix takes a two-field table, start and end, and matches it against a field of discrete values already loaded in memory. The result is a bridge table that associates each discrete value with the interval containing it.
There are three conditions the documentation mentions and that are worth memorising. First, the field holding the discrete data must be loaded before the statement. Second, the table in the basic IntervalMatch must carry exactly two fields. Third, and this surprises everyone the first time, intervals are closed at both ends: if one price ends on 28 February and the next starts on 28 February, that date belongs to both.
The extended version adds further keys. Instead of "which interval contains this date", it asks "which interval of this product contains this date". That is the one that serves slowly changing dimensions, which is the elegant name for price lists, tariffs, standard costs, salesperson assignments and org charts.
The QlikSense IntervalMatch script, commented
Let us take the case of prices per product with validity dates. First the facts, then the list, then the bridge.
// ---------- 1. FACTS ----------
// FechaVenta must exist in memory BEFORE the IntervalMatch
Ventas:
LOAD
IdVenta,
IdProducto,
Date(Floor(FechaVenta)) as FechaVenta, // no time part: avoids boundary failures
Cantidad,
CostoUnitario
FROM [lib://Datos/ventas.qvd] (qvd);// ---------- 2. PRICE LIST WITH VALIDITY DATES ----------
// Empty Hasta = current price. Replaced with a real cap date.
ListaPrecios:
LOAD
IdProducto,
Date(Floor(Desde)) as Desde,
Date(If(Len(Trim(Hasta)) = 0,
MakeDate(2099,12,31),
Floor(Hasta))) as Hasta,
Precio
FROM [lib://Datos/lista_precios.xlsx]
(ooxml, embedded labels, table is Precios);// ---------- 3. THE BRIDGE ----------
// Extended syntax: besides the date, it matches on IdProducto
Puente:
IntervalMatch (FechaVenta, IdProducto)
LOAD DISTINCT
Desde,
Hasta,
IdProducto
RESIDENT ListaPrecios;At this point Qlik generated a table with Desde, Hasta, IdProducto and FechaVenta. It also generated a synthetic key, because the bridge table shares three fields with the price list. Do not leave it there. We flatten it with a Left Join and drop what is left over.
// ---------- 4. BRING THE PRICE INTO THE BRIDGE ----------
LEFT JOIN (Puente)
LOAD
Desde,
Hasta,
IdProducto,
Precio
RESIDENT ListaPrecios;
DROP TABLE ListaPrecios;
// ---------- 5. PUSH THE PRICE DOWN TO THE FACT ----------
LEFT JOIN (Ventas)
LOAD
IdProducto,
FechaVenta,
Precio as PrecioVigente
RESIDENT Puente;
DROP TABLE Puente;// ---------- 6. METRICS YOU CAN NOW COMPUTE ----------
// In the chart, with no Set Analysis or extra mapping:
// Historical sales : Sum(Cantidad * PrecioVigente)
// Margin : Sum(Cantidad * (PrecioVigente - CostoUnitario))
// Margin % : Sum(Cantidad * (PrecioVigente - CostoUnitario))
// / Sum(Cantidad * PrecioVigente)The final model has a single fact table with the right price attached to every row. No synthetic keys, no bridge tables hanging around, no four-hundred-character expressions trying to rebuild validity at chart time. The work was done once, at load.
The overlap check nobody writes
Here is the part that separates a lab script from a production one. Because intervals are closed, two validity ranges that touch on one day duplicate that day's sale. And the duplication throws no error: it gives a bigger number.
// Run BEFORE step 5, while the Bridge is still alive
Control:
LOAD
IdProducto,
FechaVenta,
Count(DISTINCT Precio) as PreciosDistintos
RESIDENT Puente
GROUP BY IdProducto, FechaVenta;
Traslapes:
LOAD IdProducto, FechaVenta
RESIDENT Control
WHERE PreciosDistintos > 1;
DROP TABLE Control;
IF NoOfRows('Traslapes') > 0 THEN
TRACE >>> ALERTA: hay traslapes en la lista de precios;
// In production: keep the table for inspection or abort the reload
ELSE
DROP TABLE Traslapes;
END IFIt took me a good while to work out that Qlik has no Having, so the aggregation and the filter go in two steps. It is ugly. It works.
From the script to the income statement
Let us translate this into what matters to a manager. A price list that changed four times during the year, applied retroactively at today's price, distorts the historical margin by exactly the size of the price variation. In a company that raised prices 12% over the year, the first-quarter margin looks inflated by close to that same proportion. Decisions taken on that basis: which products to discontinue, which customer is profitable, which salesperson gets a bonus.
The three effects you actually notice in the operation:
- Auditable margins. The price shown on the dashboard is the same one that came out on that day's invoice. The conversation with finance changes tone once that holds.
- Performance. Resolve validity at load time, once, instead of resolving it in every chart with nested expressions. Apps that do the latter crawl whenever the user touches a filter.
- A single version of history. When every area rebuilds validity its own way, you end up with as many truths as analysts.
And the pattern does not stop at prices. It serves standard costs per period, salesperson-to-territory assignment, freight tariffs, exchange rates, plant shifts against machine downtime, recipe versions against produced batches. Anywhere an attribute has a start date and an end date, this is the mechanism.
Common mistakes with QlikSense IntervalMatch
Leaving the time part in the dates. If FechaVenta carries a time and Desde does not, the boundary comparison fails in ways that are hard to trace. Hence the Floor() in step 1. When you need second-level precision, the typical case of sensors and machine downtime, then Hasta must be the next start minus a minimal fraction, not the same instant.
Not closing the last interval. A Hasta null makes that record match nothing and the sale is left without a price. The If(Len(Trim(Hasta)) = 0, ...) in the script exists for that reason.
Ignoring the memory cost. The matching evaluates every interval against every discrete value. With two million distinct dates and fifty thousand intervals, the reload either falls over or takes forever. The fix: load only the distinct dates you need, not every unique timestamp, and limit the fact's date range before the matching.
Accepting the synthetic key. Qlik creates it and the app keeps working, so plenty of people leave it. It grows with volume and ends up being the heaviest object in the model.
Good practices for QlikSense IntervalMatch
- Build the bridge table in an intermediate layer and store it as a QVD. On incremental reloads you avoid redoing the full matching every night.
- Always keep the overlap check in the script, even when the list arrives "validated" from the ERP. It comes with overlaps. It always comes with overlaps.
- use
LOAD DISTINCTon the interval table. Price lists exported from transactional systems carry exact duplicates with a frequency that is almost funny. - Document in the script itself what an empty
Hastameans in that source. Not every source uses it the same way, and that ambiguity has cost more than one recalculation. - Check the total before and after.
Sum(Cantidad)must be identical before and after the matching; if it grew, you have an overlap.
14 March
Go back to the opening question. With this pattern in place, the answer no longer depends on somebody digging out an old spreadsheet from a shared folder: it comes out of the model, it is reproducible and anyone can audit it in thirty seconds, which is precisely what separates an information system from a collection of well-presented files.
More practical articles in the series, at this same level of detail, at hectorpincheira.com. And if your profitability app is more than two years old, check today how it computes the historical price. It probably does not compute it.




