Automatic calculation of Average for values of the datatype Enumeration

Hi All, In my data model, I have attributes (CurrentLevelOfMaturity1, CurrentLevelOfMaturity2, CurrentLevelOfMaturity3, CurrentLevelOfMaturity4) in the entity of the type Enumeration (values 1,2,3,4,5) to function as a drop-down in the application page.   I would like the average of these values to be automatically calculated in the filed of “AverageOfCurrentValueOfMaturity” which I know I can achieve by writing an expression for a change object in the Microflow. However, I have tried this before when the attribute’s datatype was Integer and that I change the datatype of the attribute “AverageOfCurrentValueOfMaturity” to decimal. In this case, the values are calculated automatically when I call the microflow  on the “on change” even of the data field.   In the case of the datatype of the attribute being Enumeration, I am not aware how I could define the expression for calculating the average of the values.   Kindly assist. Regards Anirudh
2 answers

An enumeration is no numeric value. If you want to calculate an average, you need to do this on your own.

→ Create a variable with value 0

→ Parse all your enumeration attributes to integer or decimal and add it to your variable. You now have the sum of all attributes

→ divide your variable by the number of attributes

You can also do this in a single expression without using the variable.
(parseInteger(getCaption($Object/Attribute)) + parseInteger(getCaption($Object/Attribute2)) + ...) : number of attributes.

You can also use the getKey() method if you need to use the key instead of the caption.


That works perfectly as expected

Thank you