Hi Sam,
Thanks for your response and the additional information. To create the table you need, we can utilize the transform function along with a capsule expression to iterate through each product run capsule. Within this loop we will calculate the previous year averages and dynamically set these to capsule properties based on the Product ID. If you're not familiar with transforms and capsule expressions, here is a good Tips and Tricks article.
Below is an example of formula code you can integrate with your existing Product Type signal to condition formula.
// existing $product_type.toCondition('Product ID') code here ...
// I am assuming this is defined as $product_condition
// if necessary, define your measurement signals filtered for $good_runs
$a_good = $a.within($good_runs)
$b_good = $b.within($good_runs)
$b_good = $b.within($good_runs)
$months = months() // monthly periodic condition
// Loop through each capsule in $product_condition and calculate last year's measurement averages
$product_condition.transform($capsule -> {
$productid = $capsule.property('Product ID') // get Product ID from the current capsule
// Extract a monthly capsule from $months one year prior to the current capsule. Note that your current capsule could span two months.
// .first() selects the month based on the start month of the capsule. Change this to .last() if you want the ending month.
$previous_year_month_capsule = $months.toGroup(capsule($capsule.startKey()-1y,$capsule.endKey()-1y)).first()
// Calculate scalar averages over the previous year month capsule, filtered for current product ID
$a_avg = $a_good.within($product_condition.keep('Product ID', isEqualTo($productid))).average($previous_year_month_capsule)
$b_avg = $b_good.within($product_condition.keep('Product ID', isEqualTo($productid))).average($previous_year_month_capsule)
$c_avg = $c_good.within($product_condition.keep('Product ID', isEqualTo($productid))).average($previous_year_month_capsule)
// Set averages as capsule properties
$capsule.setProperty('Previous Year Month Average A', $a_avg)
.setProperty('Previous Year Month Average B', $b_avg)
.setProperty('Previous Year Month Average C', $c_avg)
})
From here, create a Condition Table and use the Columns selector to pick each of the Capsule properties you want in the table.
Here's an example of how you might set up the Condition Table using the Example >> Batch Data >> Reactor 1 data source:
We'll mostly ignore my previous reply 😅 - helpful if you want the previous year average signals for analysis but not for the table filtered by Product ID.
Hope this helps!
Dan