Gap Filling Forward to Current Time494

MikeMills private msg quote post Address this user
Sometimes you want to use a dependent stream's last value in another derivation formula. You also want a historical record inside that stream in case the derived stream needs to be recalculated.

What you want is a stream that forward gap fills with the last value up to the the current time. This thread explains how to configure for this.

Here's a good use case:
Assume you're calculating energy cost. You have a kwh stream and a rate stream. The rate changes about once a year, or at most once a day. You want derivation to pickup the correct rate. You also want derivation to use the latest rate, until a new rate is entered.

The trick is to setup the Rate stream correctly. We can create a DAY Interval Rate stream and gap fill it properly (this assumes the rate changes at most once a day). We can setup derivation for that stream to forward gap fill using the last rate entered into the stream. It will fill every day with the current rate up to the current time. Here's how:

Create the Day Interval Rate Stream:

Configure gap filling to fill all days in-between two rate entries with the previous value:

Save the component, double click the stream to open stream viewer/editor and enter in known rates. Only enter in the rate on the day the rate starts. Then save the stream. When the stream samples are saved, interval gaps between the days are automatically filled with the previous value.

Edit the component again and setup derivation on the Rate stream and save the component:

You can now use the rate stream in your energy cost calculation stream (which is derived). Ensure you pick the right cycle when using the rate stream as a dependent. Select Month/Last if you are doing monthly energy calcs or Day/Last if you're doing Daily calcs.

How does it work? The trick is to fill all of the days for the rate stream with a rate value. Gap filling will do this as you're entering in historical rate values and saving the stream, but it will not forward gap fill to the current date. That's where derivation comes in. Derivation will always run about every 2-3 minutes for the rate stream since it is not waiting for any dependent values to arrive. It will run and fill the current day being evaluated with the stream's last value which is the previous day - thus forward gap filling up to the current day/time.
Post 1 IP   flag post
MikeMills private msg quote post Address this user
This technique is similar to the derivation stream Kicker technique (adding Kicker keyword so others can find this thread).

Kicker refers to kicking a stream to be derived without waiting for dependent streams. It is used to force derivation calculations up to the current time.
Post 2 IP   flag post
JLS private msg quote post Address this user
Thank you Mike, this worked great!
Post 3 IP   flag post
2965 3 3
Log in or sign up to compose a reply.