Join the Team Forms community

N
D
M
T
T

Generate a numeric value from two text inputs

Updated 3 weeks ago

I'm trying to generate a numeric Risk Rating based on two text values that correspond with a numeric value. For example a Likelihood of Rare, Unlikely, Possible etc. Also, we have a Consequence of Critical, Major, Moderate etc. When the two are in a matrix the X and Y values give a Risk Rating. The higher the Likelihood and the higher the Consequence means it's a higher risk. How do I generate a matrix based on two values to produce a single result.

Example below.

The numeric value is probably not needed, even the rating alone will be OK.

Open to any suggestions.


Thanks.

Marked as solution

Hi Ray,

You can use a calculated value to display a score based on the two selections (probability and impact). For the example below I have used the standard 5 x 5 risk matrix calculation as it is simpler than the one you have posted in your screenshot, however the concept still applies but you will need to modify the JavaScript if you would like to use the specific scores shown in your screen shot.


1. Drag and drop a drop-down menu into your form to represent the probability rating. Under the "data" tab of component add the various labels for probability and in the "value" column place a number. This is shown in the below:

  1. Drag and drop a drop-down menu into your form to represent the impact rating. Under the "data" tab of component add the various labels for impact/consequence and in the "value" column place a number. This is shown in the below:


  2. Drag and drop a Text field into the from for the calculated score

  3. Navigate to the data tab and add the following JavaScript expression for the calculated score. Note, you may need to modify this expression for your specific form.

    JavaScript
    const ratingMatrix = [
        ['Medium'  , 'High'    , 'Very High' , 'Extreme'  , 'Extreme'   ],
        ['Medium'  , 'Medium'  , 'High'      , 'Very High', 'Extreme'   ],
        ['Low'     , 'Medium'  , 'Medium'    , 'High'     , 'Very High' ],
        ['Very Low', 'Low'     , 'Medium'    , 'Medium'   , 'High'      ],
        ['Very Low', 'Very Low', 'Low'       , 'Medium'   , 'Medium'    ],
    ]
    
    const probabilityIndex = 5 - (data.probability || 0)
    const impact = (data.impact || 0) - 1
    const rating = ratingMatrix[probabilityIndex][impact]
    value = rating


Here is an example of the final output:

View full solution
A
R
2 comments·3 replies

Hi Ray,

You can use a calculated value to display a score based on the two selections (probability and impact). For the example below I have used the standard 5 x 5 risk matrix calculation as it is simpler than the one you have posted in your screenshot, however the concept still applies but you will need to modify the JavaScript if you would like to use the specific scores shown in your screen shot.


1. Drag and drop a drop-down menu into your form to represent the probability rating. Under the "data" tab of component add the various labels for probability and in the "value" column place a number. This is shown in the below:

  1. Drag and drop a drop-down menu into your form to represent the impact rating. Under the "data" tab of component add the various labels for impact/consequence and in the "value" column place a number. This is shown in the below:


  2. Drag and drop a Text field into the from for the calculated score

  3. Navigate to the data tab and add the following JavaScript expression for the calculated score. Note, you may need to modify this expression for your specific form.

    JavaScript
    const ratingMatrix = [
        ['Medium'  , 'High'    , 'Very High' , 'Extreme'  , 'Extreme'   ],
        ['Medium'  , 'Medium'  , 'High'      , 'Very High', 'Extreme'   ],
        ['Low'     , 'Medium'  , 'Medium'    , 'High'     , 'Very High' ],
        ['Very Low', 'Low'     , 'Medium'    , 'Medium'   , 'High'      ],
        ['Very Low', 'Very Low', 'Low'       , 'Medium'   , 'Medium'    ],
    ]
    
    const probabilityIndex = 5 - (data.probability || 0)
    const impact = (data.impact || 0) - 1
    const rating = ratingMatrix[probabilityIndex][impact]
    value = rating


Here is an example of the final output:

That is perfect. Thanks heaps. I was trying IF statements, but it got too much for me.

Thanks again.

Hi Anthony,

Following on from this question, we have one Initial risk Calculation followed by x number of actions that can be used to mitigate the risk. Each of these actions have a Consequence and a Likelihood. this is almost like a one to many. The initial data is in a Panel component and the JS is as per your example, that works fine.

I have added the mitigation steps in a Data Grid Component, single column, with an Add a new Action button at the bottom that adds x number of actions to mitigate that risk.

The problem now is that the new Risk Rating calculation uses the field names in the top section (as in data.likelihood) many times and the resulting calc never updates based on the new values for each additional option. Each new Action needs to have likelihood1 (for example, as the API key name), the likelihood3 etc etc.

Any ideas?


Thanks

Hi Ray,

Within a data-grid you can access the value of a row using the row variable. For example, if you have a column for consequence and a column for likelihood you can have a calculated field which multiplies the two using something like the example below. Note that you will need to modify the example for your specific data-grid.


Plain Text
value = row.likelihook * row.consequence

Thanks Anthony, I will try. I have found a different way to do it though. So should be good.