# Expression for Cpk and 3 sigma or tips for how to get there?

**URL:** <https://forum.inductiveautomation.com/t/expression-for-cpk-and-3-sigma-or-tips-for-how-to-get-there/42246>\
**Category:** Ignition\
**Created:** [January 14, 2021, 4:14pm UTC](https://forum.inductiveautomation.com/t/expression-for-cpk-and-3-sigma-or-tips-for-how-to-get-there/42246 "2021-01-14T16:14:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rusty](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rusty/32/19859_2.png) [@Rusty](https://forum.inductiveautomation.com/u/Rusty)\
**Post date:** [January 14, 2021, 4:14pm UTC](https://forum.inductiveautomation.com/t/expression-for-cpk-and-3-sigma-or-tips-for-how-to-get-there/42246/1 "2021-01-14T16:14:20Z")

</div>

Hello,

This might be a simple matter of using an expression correctly:

I am trying to get the 3 sigma and Cpk values for certain process parameters. I am running a script which aggregates the tag history using the SimpleAvg and StdDev methods, this works fine. in order to calculate the Cpk, I had also planned on calculating it via expression tag with the following expression:

```auto
//Cpk = min(USL - μ, μ - LSL) / (3σ)
//where USL and LSL are the upper and lower specification limits, 
//μ is the process mean, and σ is the process standard deviation.
value1 = ({[.]HeightUSL}-{[.]HeightAvg})
value2 = ({[.]HeightAvg}-{[.]HeightLSL})
value3 = (3*{[.]HeightDev}) //3 sigma
value4 = (value1 / value3) //value used if value1 is lower
Value5 = (value2 / value3) //value used if value2 is lower
if(value1 < value2, value4, value5) //checks if value1 or value2 is lower

```

The tag is showing an “error\_configuration” message. How can I fix or improve this expression?

Do you know any simpler method of getting to the Cpk values?

Thanks

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [January 14, 2021, 4:24pm UTC](https://forum.inductiveautomation.com/t/expression-for-cpk-and-3-sigma-or-tips-for-how-to-get-there/42246/2 "2021-01-14T16:24:08Z")

</div>

You say your writing an expression buy your laying it out like a python script. That won’t work. You also have value 5 written as “Value5” up top and “value5” below. Try:

```auto
if(({[.]HeightUSL}-{[.]HeightAvg}) < ({[.]HeightAvg}-{[.]HeightLSL}), 
     (({[.]HeightUSL}-{[.]HeightAvg}) / (3*{[.]HeightDev})), 
     (({[.]HeightAvg}-{[.]HeightLSL}) / (3*{[.]HeightDev})))

```

---

<div class="post-metadata">

**Author:** ![Rusty](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rusty/32/19859_2.png) [@Rusty](https://forum.inductiveautomation.com/u/Rusty)\
**Post date:** [January 14, 2021, 7:48pm UTC](https://forum.inductiveautomation.com/t/expression-for-cpk-and-3-sigma-or-tips-for-how-to-get-there/42246/3 "2021-01-14T19:48:17Z")

</div>

> [@bpreston](#):
>
> if(({[.]HeightUSL}-{[.]HeightAvg}) \< ({[.]HeightAvg}-{[.]HeightLSL}), (({[.]HeightUSL}-{[.]HeightAvg}) / (3\*{[.]HeightDev})), (({[.]HeightAvg}-{[.]HeightLSL}) / (3\*{[.]HeightDev})))

Thank you, that worked!
