# Changing Formula value based on time

## Recommended Posts

Hi, I've been looking around but not sure if there's a way to do this:

Let's say the cost of something is \$10 before Jan 1 2020, and I know it changes to \$20 after Jan 1 2020.

Is there a way I can put this all into one formula, so that the signal would be 10 before Jan 1 2020, and 20 after Jan 1 2020? It would look like a stepwise signal.

Thanks!

• 1
##### Share on other sites

• Seeq Team

Hi Dominic,

You can use the splice function in Formula to complete this request. I'm assuming your cost changes each year so you may want to splice in a different cost for each year. For example, you can use the following Formula to say take the current cost of \$20 and splice in \$10 cost for all of 2019 so that on January 1st, it steps up to the new cost:

`20\$.tosignal().splice(10\$.tosignal(), condition(1y, capsule('2019')))`

Let me also break this Formula down a bit so that you understand it better. In the first part, we are saying take a value of \$20 (as a signal) as the default result, which means that anytime before or after 2019 (in this case), the value would equal \$20. However, when the capsule is present in the condition in the splice condition is met (in this case it's a capsule for all of 2019), the \$10 signal will be spliced instead of the \$20 signal. I also want to note that the '1y' argument in the condition is the maximum duration. If you wanted to expand the capsule to be longer than 1 year, you would also need to edit that value.

If you want to add additional years at the \$10 value, you can simply add them as more capsules in the condition argument. For example, adding 2018:

`20\$.tosignal().splice(10\$.tosignal(), condition(1y, capsule('2019'), capsule('2018')))`

If you want to add different values instead (let's say \$15 for 2018), you could use the following modification:

`20\$.tosignal().splice(10\$.tosignal(), condition(1y, capsule('2019'))).splice(15\$.tosignal(), condition(1y, capsule('2018')))`

• 3
##### Share on other sites

Thanks Joe! This works for a 1 year format.

If I wanted to get more specific for the date range on the price, let's say it's 10\$ between Feb 1 2019 and May 12 2019, how would I adjust the date range in the capsule?

I tried using

`20.toSignal().splice(10.tosignal(), condition(100d,capsule('2019-02-01','2019-05-12')))`

but I don't think I'm using the capsule or the condition function right.

Thanks!

##### Share on other sites

• Seeq Team

Hi Dominic,

In order to specify both start and end time, you have to specify the exact time rather than just the day as the day or year option creates both a start and end time (for example, '2019' created both a start of Jan 1, 2019 at 12:00 AM and an end of Jan 1, 2020 at 12:00 AM). Therefore, your function would need to be formatted like this:

`20\$.tosignal().splice(10\$.tosignal(), condition(100d, capsule('2019-02-01T00:00Z','2019-05-12T00:00Z')))`

• 2
##### Share on other sites

Awesome, worked like a charm. Thanks so much Joe!