---
title: "Perform Miscellaneous Calculations 3.0"
id: "perform-miscellaneous-calculations-3-0"
project: "Knowledge Base"
url: "https://docs.sepasoft.com/articles/knowledge-base/perform-miscellaneous-calculations-3-0"
updated: 2026-07-23T18:08:29Z
---

# Perform Miscellaneous Calculations 3\.0

## Overview

Custom calculations can be defined in the Misc. section of the MES Scripts under SPC Calculations. SPC module allows you to execute your miscellaneous calculations through scripting.

### Applies To and Version Info

This feature applies to the SPC 3.0 module.
 ### Steps

1. Select MES Scripts in your Project Browser - this is available in the project you designate as your MES Gateway project.
2. Create a new Calculation by right-clicking the table in the Misc. section and adding a script. Scripts can be added to folders for organization.

![](/resources/Storage/knowledge-base/perform-miscellaneous-calculations-3-0/image2022-12-27_9-41-57.png)
 3. Name the calculation to your choosing.

4. In this example, we will create a custom Anderson-Darling Test (ADT). Set the Script type to Anderson-Darling Test (Adt).

5. Add your own script to the script window. It is suggested to use existing scripts as a template or starting point to your own scripts.

## 

## Details

The corresponding Miscellaneous Calculations Event is created for each calculation. Refer Event Objects for more details on how to use this event.

Info

| ![Information](/resources/Storage/knowledge-base/Info.png) | Custom calculations can also be done using the tag change scripts where MiscCalcEvent will execute the calculation using system.mes.spc.analysis.executeMiscCalculation |
| --- | --- |

![](/resources/Storage/knowledge-base/perform-miscellaneous-calculations-3-0/image2022-12-27_9-43-46.png)
 ## Scripting

This example calculates the CPK and PPK using the default Cppp calculation included with the module.

![](/resources/Storage/knowledge-base/perform-miscellaneous-calculations-3-0/image2022-12-27_9-52-50.png)

### Example 1

This example calculates CPK and PPK via the Cppp misc calculation event.


Code

```
locationPath = 'Enterprise\El Dorado Hills\Packaging Area\Packaging Line 1\Inspection Station 1'
filters = 'FromDate=2022-11-26 09:00:00|ToDate=2022-11-28 23:30:00|Location=' + locationPath

definitionName = 'Nonconformity'
attribute = 'Color'
controlLimits = 'CpPp LSL,CpPp USL'

settings = system.mes.spc.analysis.createSettings(definitionName, attribute, filters, controlLimits, '', 'Process Capability and Performance')
result = system.mes.spc.analysis.executeMiscCalculation(settings, 'Cppp')

print result.getValue('PpStdDev')
print result.getValue('CpStdDev')
print result.getValue('Ppk')
print result.getValue('Cpk')
  
```

### Example 2

This example calculates the ADT (Anderson Darling Test).

Code

```
locationPath = 'Enterprise\El Dorado Hills\Packaging Area\Packaging Line 1\Inspection Station 1'
filters = 'FromDate=2022-11-26 09:00:00|ToDate=2022-11-28 23:30:00|Location=' + locationPath

definitionName = 'Nonconformity'
attribute = 'Color'

settings = system.mes.spc.analysis.createSettings(definitionName, attribute, filters, '', '', 'Anderson-Darling Test')
result = system.mes.spc.analysis.executeMiscCalculation(settings, 'Adt')

print 'Mean: ', result.getValue('Mean')
print 'StdDev: ', result.getValue('StdDev')
print 'S: ', result.getValue('S')
print 'Ad: ', result.getValue('Ad')
print 'AdStar: ', result.getValue('AdStar')
print 'PValue: ', result.getValue('PValue')
if result.getValue('PValue') > 0.05:
	print 'Since the p-value is large (>0.05), we accept the null hypotheses that the data are from a normal distribution.'
else:
	print 'Since the p-value is low (<=0.05), we reject the null hypotheses that the data are from a normal distribution'
```

 ### Example 3

This example calculates the Cp (Process Capability).

Code

```
locationPath = 'Enterprise\El Dorado Hills\Packaging Area\Packaging Line 1\Inspection Station 1'
filters = 'FromDate=2022-11-26 09:00:00|ToDate=2022-11-28 23:30:00|Location=' + locationPath

definitionName = 'Nonconformity'
attribute = 'Color'

controlLimits = 'Cp LSL,Cp USL,Cp Target'

settings = system.mes.spc.analysis.createSettings(definitionName, attribute, filters, controlLimits, '', 'Process Capability')
result = system.mes.spc.analysis.executeMiscCalculation(settings, 'Cp')
print result.getValue('Cp')
```

 ### Example 4

This example calculates the Control limit  (Individual) using the default Control limit calculation.


Code

```
locationPath = 'Enterprise\El Dorado Hills\Packaging Area\Packaging Line 1\Inspection Station 1'
definitionName = 'Single Attribute'
sampleDefObj = system.mes.loadMESObject(definitionName, 'SampleDefinition')
attribute = 'Diameter'
limitName = 'Individual LCL'
toDate = system.date.now()
fromDate = system.date.addHours(toDate, -2)

results = system.mes.spc.controllimit.calcControlLimitValue(sampleDefObj, locationPath, attribute, limitName, fromDate, toDate)
print results['calculatedValue']
```
