--- tags: - data collection alias: tutorial-datacollection-edc-parameters-calculated-customjsonatafunctions timetoread: true description: "Custom JSONata functions were added, including range, standard deviation, and date functions" --- # Custom JSONata Functions Some custom JSONata functions were added to the existing out-of-the-box functions. Below is a list of what was added, as well as an explanation of what these functions do and how to use them. ## Range The **Range** function is not part of the standard JSONata suite of functions, so it was developed specifically for Critical Manufacturing MES. It takes a single argument which must be an array of numbers and it returns the difference between the largest and smallest values of the provided set. The syntax is as follows: ```c# // The difference between the larges and smallest readings of the parameter CP_Demo_79459_Dec01 $range(Parameters.CP_Demo_79459_Dec01.**.Value) ``` ## Standard Deviation Like the **Range** function, the **Standard Deviation** is not part of the standard JSONata functions. It takes a single argument which must be an array of numbers, and returns the standard deviation of the provided set. Below is an example of how this function can be used, as well as the algorithm it uses: !!! note This implementation assumes the provided set is the complete population, not just a sample. For more information, see [Standard Deviation Calculator](https://www.calculator.net/standard-deviation-calculator.html) ```c# // The standard deviation of all the readings from parameter CP_Demo_79459_Dec01 $range(Parameters.CP_Demo_79459_Dec01.**.Value) // The algorithm behind the scenes. "values" is the input set of values double average = values.Average(); double sumOfDerivation = 0; foreach (double value in values) { sumOfDerivation += Math.Pow(value - average, 2.0d); } sumOfDerivation /= values.Count() > 0 ? values.Count() : 1; return (double)Math.Sqrt((double)sumOfDerivation); ``` ## Today This function takes no arguments and returns the current local date, with the time component set to 00:00:00.000. This is the function that the `@Today` token uses. The offset is defined using the UTC offset of the customer, but it falls back to the UTC offset of the host if the UTC of the customer cannot be determined: ```c# $today() // 2024-04-18T00:00:00.000+01:00 ``` ## Today (milliseconds) This function also takes no arguments and like the `$today()` function, this returns the current local date but in the Unix timestamp format: ```c# $todayMillis() // 1713394800 ```