Hello @lowercas3
Thank you very much for using our plugin.
You can insert a calculated field in the form and enter the following equation:
AVERAGE(1,2,3,4);
Best regards.
Sorry I should have clarified. How do I create a field to accept the user input as a sequence of numbers separated by commas?
Hello @lowercas3
In this case, you should use a “Single Line Text” instead of a number field because the user will enter values that are not specific numbers. However, in this case, you should transform the information entered by the user into a numbers array.
For example, assuming the “Single Line Text” is the fieldname123, the equation in the calculated field would be:
AVERAGE(fieldname123|r.replace(/[^\.\d\,]/g,'').split(','))
The field’s name with the |r modifier allows accessing the raw field’s value.
Best regards.
Thank you. This works well. Let’s say I want to take the average of the square of each of the values. How would that work?
(fieldname123|r.replace(/[^\.\d\,]/g,”).split(‘,’)) is the array of numbers – so I’d like to apply a square operation on each element of the array and then take the average.
Hello @lowercas3
The SUM operation accepts a callback function as the last parameter. So, you can implement the equation as follows:
(function(){
var list = fieldname123|r.replace(/[^\.\d\,]/g,'').split(','),
count = list.length;
return SUM(list, function(x){return POW(x,2);})/count;
})()
Learn more about the available operations by visiting the following link:
https://cff.dwbooster.com/documentation#mathematical-module
Best regards.
Hello,
I tried this code and it doesn’t appear to recognize negative numbers in the input list as being different from positive numbers. So 10, -10, 10 will give the same result as 10, 10, 10. Any idea what I might be doing wrong? thanks.
(function(){
var list = fieldname15|r.replace(/[^\.\d\,]/g,'').split(','),
count = list.length;
return SUM(list, function(x){return x;})/count;
})()
-
This reply was modified 3 years, 5 months ago by
lowercas3.
Hello @lowercas3
Please, modify the regular expression as follows: /[^\-\.\d\,]/g
Best regards.
Hello, thank you this works. The only issue is when I reduce the series to one number. It doesn’t provide a result. Any idea how we can accommodate this case?
Hello @lowercas3
In this case, you must ensure the value is treated as a text and not a number before applying the replace method:
(function(){
var list = (fieldname15|r+'').replace(/[^\.\d\,]/g,'').split(','),
count = list.length;
return SUM(list)/count;
})()
Best regards.