tip Creating Periodic Conditions Relative to Now

Recommended Posts

For reporting purposes, I want to calculate statistics based on the most recent period(capsule) and display that along with the periods immediately preceding it. This can be done in Organizer using the custom date range by creating a Periodic Condition and selecting the capsule closest to or offset by one from the end.

The same date ranges or capsules relative to now can be created in Seeq Workbench as well.

Organizer:

Workbench:

We create the same condition as the above Organizer in Workbench by following the methods below. The first method defines how to create conditions for current and previous conditions for years, days, weeks, shifts. The second method includes an extra step that is necessary for current and previous months and quarters since the exact duration of these periods can vary based on the number of days each month.

Method 1 - when the length of time in each period is definitive (e.g. year, week, day, shift). This example shows how to create conditions for "Current Week" and "Previous Week"

1. Create a Periodic Condition for "Weekly" using the Periodic Condition tool.

2. Create a Condition around the current time ("Now") using Formula -->

`condition(1min, capsule(now() - 1min, now()))`

3. Use the Composite Condition tool to create a condition for "Current Week" when the Periodic Condition "Weekly" touches the tiny capsule at "Now".

4. Use Formula to create a condition for the "Previous Week" -->

`\$currentWeek.beforeStart(7d)`

Method 2 - when the length of time in each period is variable (e.g. month, quarter). This example creates a condition for "Current Month" and "Previous Month"

1.  Create a Periodic Condition for "Monthly" using the Periodic Condition tool.

2. Create a Condition around the current time ("Now") using Formula -->

`condition(1min, capsule(now() - 1min, now()))`

3. Use the Composite Condition tool to create a condition for "Current Month" when the Periodic Condition "Monthly" touches the tiny capsule at "Now".

4. Use Formula to create a Condition for the last day of the last period (in this case "Last Day of the Last Month")

`\$currentMonth.beforeStart(1d)`

5. Use the Composite Condition tool to create a condition for the "Previous Month" when the Periodic Condition "Monthly" touches the "Last Day of Last Month".

Content Verified DEC2023

Edited by Synjen Marrocco
Cleaning up for 2023 Swarm
• 2
Share on other sites

• 7 months later...

Thanks for the post, Allison!

I wanted to share how I took what you did and made it into rolling a "year to date" (YTD) metric, and other comparable metrics.

I work in hydroelectric generation, so my utility operates a few dams. One of the things we want to track is how close our upstream water level (headwater) gets to our buffered operating limits (in this case I'm looking at buffered lower limit dips). Here's a screenshot of the example scorecard metrics I created:

And here are the dependency trees:

Here's how I did it:

So, starting from the deepest part of the trees:

• ‘Yearly 1’ is common to all three. It is standard Periodic Condition for Yearly capsules.
• ‘Now Condition’ follows the forum post. Make this formula: condition(1min, capsule((now()-1min), now()))
• ‘Year Ago Now’ is based on the ‘Now Condition’ but you subtract off another year. Make this formula: condition(1min, capsule((now() - 1min - 1year), (now() - 1year)))

• ‘Current Year’ is a composite condition of ‘Yearly 1’ and ‘Now Condition’ using “Touches”
• ‘Last Year’ is a composite condition of ‘Yearly 1’ and ‘Year Ago Now’ using “Touches”
• ‘Rolling Year Condition’ is a formula. condition(1year, capsule((now()-1year), now()))

• ‘Year to Date’ is a composite condition of ‘Current Year’ and ‘Rolling Year Condition’ using “Intersection” (i.e. when is it both the current year and happening within the last year.)
• ‘Last Year to Date’ is a composite condition ‘Last Year’ and ‘Rolling Year Condition’ using “A minus B” (i.e. when is it last year but not within the last rolling year.)

• Then you can create your usual value based conditions. I used RI Headwater less than 610.

• Then you create your metrics! Here’s the screenshot of the Year to Date metric. To get Last YTD, you simply change the condition at the bottom to ‘Last Year to Date.’ The metrics refresh when you refresh the screen!

• 2
Share on other sites

This is an awesome solution Peter!

Share on other sites

• 1 year later...

Hi! I'm hoping to use this in a dashboard that displays this month to date as well as the previous 3 months data. Is it possible to use this method with a splice function so that this is all displayed on one signal/metric?

Edited by Ielish Goble
Share on other sites

Multiple conditions that contain current, previous, or other specific timeframes can be combined into one condition using the combineWith() function. The above method may not be required if you would like to have your aggregated signal calculated across every capsule within a condition (i.e. every week in a weekly condition).

`combineWith(\$current_week, \$previous_week, \$week_N)`