# Selecting Capsules within a Condition

## Recommended Posts

• Seeq Team

In some cases you may want to do a calculation (such as an average) for a specific capsule within a condition. In Seeq Formula, the toGroup() function can be used to get a group of capsules from a condition (over a user-specified time period). The pick() function can then be used to select a specific capsule from the group. The Formula example below illustrates calculating an average temperature for a specific capsule in a high temperature condition.

```// Calculate the average temperature during a user selected capsule of a high temperature
// condition. (The high temperature condition (\$HighT) was created using the Value Search tool.)
//
// To prevent an unbounded search for the capsules, must define the search start/end to use in toGroup().
// Here, \$capsule simply defines a search time period and does not refer to any specific capsules in the \$HighT condition.
\$capsule = capsule('2019-06-19T09:00Z','2019-07-07T12:00Z')

// Pick the 3rd capsule of the \$HighT condition during the \$capsule time period.
// We must specify capsule boundary behavior (Intersect, EnclosedBy, etc.) to
// define which \$HighTcapsules are used and what their boundaries are (see
\$SelectedCapsule = \$HighT.toGroup(\$capsule,CapsuleBoundary.EnclosedBy).pick(3)

// Calculate the temperature average during the selected capsule.
\$Temperature.average(\$SelectedCapsule)```

Edited by John Cox
• 1
##### Share on other sites
• 1 year later...

Here's another method to pick a specific capsule within a condition. In this example, the user want to pick the first capsule from condition 2 within condition 1.

Use formula tool:

```\$condition1
.removeLongerThan(1d)
.transform(\$c ->
\$condition2.removeLongerThan(1d).toGroup(\$c).pick(1))```

The output:

Edited by Nuraisyah Rosli

## Create an account

Register a new account