Skip to main content
kenneth kam chuh21426993
Known Participant
May 3, 2023
Answered

Risk Calculation matrix

  • May 3, 2023
  • 2 replies
  • 2179 views

I have this risk calculation matrix (Table below) at work that I need to automate

Briefly, the risk can be calculated by Likelihood and the consequences of an hazard.

e.g. if a user select one cell ("Likelihood") with D and selects the second cell ("Consequences") with 3. Then I want the third cell showing the risk calculated to be M.

The problem is there are so many combinations here, so I don't know what to do.

Anyone can help with the JavaScript of this?

 

This topic has been closed for replies.
Correct answer Nesa Nurani

You can use this as custom calculation of 3rd field:

var L = this.getField("Likelihood").valueAsString;
var C = this.getField("Consequences").valueAsString;
var S = L+C;
if(S=="A1"||S=="B1"||S=="B2"||S=="C2"||S=="D3"||S=="D4"||S=="E3"||S=="E4"||S=="E5")
event.value = "M";
else if(S=="C1"||S=="D1"||S=="D2"||S=="E1"||S=="E2")
event.value = "L";
else if(S=="A2"||S=="A3"||S=="B3"||S=="B4"||S=="C3"||S=="C4"||S=="D5")
event.value = "H";
else if(S=="A4"||S=="A5"||S=="B5"||S=="C5")
event.value = "VH";
else
event.value = "";

2 replies

try67
Community Expert
May 7, 2023

Is there a logic behind it, or is it pretty much arbitrary what the result is for each combination?

If the latter you'll need to specify it for each combination in your code, using a set of if-else conditions, or a 2D array, as was suggested.

Bernd Alheit
Community Expert
May 7, 2023

For the matrix you can use an array of arrays.

kenneth kam chuh21426993
Known Participant
May 8, 2023

Apologies, I am quite new to JavaScript and bit of a noob. 
I think I need to do something like this. but not sure how to continue the rest....

C = consequences 

L = Likelihood 

R = Risk 

 

If the user types in 1 in the "C" cell and C in the "L" cell, I want the answer to return as "L" (Low risk)..

So far I have attempted this but I dunno how to do the rest. 

var C=[[1],[2],[3],[4],[5]];

var L=[[A],[B],[C],[D],[E]];

var R=[["M","M","L","L","L"],["H","M","M","L","L"],["H","H","H","M","M"],["VH","H","H","M","M"],["VH","VH","VH","H","M"]];
Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
May 8, 2023

You can use this as custom calculation of 3rd field:

var L = this.getField("Likelihood").valueAsString;
var C = this.getField("Consequences").valueAsString;
var S = L+C;
if(S=="A1"||S=="B1"||S=="B2"||S=="C2"||S=="D3"||S=="D4"||S=="E3"||S=="E4"||S=="E5")
event.value = "M";
else if(S=="C1"||S=="D1"||S=="D2"||S=="E1"||S=="E2")
event.value = "L";
else if(S=="A2"||S=="A3"||S=="B3"||S=="B4"||S=="C3"||S=="C4"||S=="D5")
event.value = "H";
else if(S=="A4"||S=="A5"||S=="B5"||S=="C5")
event.value = "VH";
else
event.value = "";