# Representative capsules based on capsule duration / signal metrics or how to cast metrics to scalar

## Recommended Posts

Dear community,

I want to identify representative capsules based on the capsule duration.

What I did so far is:

1. Identify capsules

2. Create a signal from condition that represents the capsule duration.

3. Calculate average capsule duration and percentiles of interest from this signal using metrics

4. Use these metrics to identify capsules that are within a certain range around the average or between two percentiles.

What I would like to do next and could not accomplish so far is:

By now step 4 works when entering the respective criterion to a value search by hand. Now I would like to do that dynamically, i.e., calculate the metrics for the displayed time range and directly get capsules that satisfy the criterion given above. After trying around for some time, this seems to be possible using formula: I tried to use the metrics directly, but the function I tried to use (InBetween) does not accept metrics as input. I also tried to calculate the metrics directly in formula to avoid wrong data types, but that was also not successful. It sems to get down to explicitly convert the signal metrics to scalar, but I also fail to do that.

As I am quite new to seeq, I would appreciate if there were some hints on this: Is it possible? Did I choose the correct approach? Are there other, even simpler ways to accomplish that.

##### Share on other sites

• Seeq Team

Hi mKaiser,

The main constraint here is calculation based on display date range is possible via simple metric only.

I have one suggestion and please let me know your thought and correct me too if I'm not capturing correctly your criteria.

Step 1 & 2 similar as yours.

Step 3 : Set the date range of interest using the manual condition.

Step 4 : Calculate the average and percentile using Signal from condition and bounded it to Step 3 condition.

Step 5: This is another tricky step as you need to define the date range in identifying the final condition. Example in the last 6month.

`condition(6mo,capsule(now()-6mo,now()))`

Step 6 : Use value search and composite condition to define the final output. I have these functions in one formula. I am not 100% sure whether I understand this final criteria but let me know if you need further help.

```//isbetween two percentile signals or certain range above average

(\$step2 <= \$percentile_90.aggregate(startValue(true), \$step5, durationKey())
and \$step2 >= \$percentile_80.aggregate(startValue(true), \$step5, durationKey()))
or
(\$step2 > \$average.aggregate(startValue(true), \$step5, durationKey()))```

So each time you change the date range at the manual condition, the whole calculation will automatically recalculate limited to step5 definition.

Edited by Sharlinda Salim

## Create an account

Register a new account