> ## Documentation Index
> Fetch the complete documentation index at: https://learn.nextedy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Formula Examples

> Ready-to-use formula configurations for common Nextedy RISKSHEET scenarios including RPN calculation, risk matrices, title generation, field concatenation, and cross-row aggregation.

export const LastReviewed = ({date}) => {
  if (!date) return null;
  const formatted = new Date(`${date}T00:00:00Z`).toLocaleDateString("en-US", {
    year: "numeric",
    month: "long",
    day: "numeric",
    timeZone: "UTC"
  });
  return <p className="mt-10 text-sm text-gray-400 dark:text-zinc-500 not-prose">
      Last reviewed on {formatted}
    </p>;
};

## RPN Calculation (FMEA)

### Initial RPN

Calculates the Risk Priority Number by multiplying severity, occurrence, and detection ratings per the AIAG & VDA FMEA Handbook.

```yaml theme={null}
formulas:
  commonRpn: "function(info){ var value = info.item['occ']*info.item['det']*info.item['sev']; return value?value:null;}"
```

| Input Field | Description                    |
| ----------- | ------------------------------ |
| `sev`       | Severity rating (1-10 scale)   |
| `occ`       | Occurrence rating (1-10 scale) |
| `det`       | Detection rating (1-10 scale)  |

**Column configuration:**

```yaml theme={null}
- id: rpn
  header: RPN
  type: int
  formula: commonRpn
```

### Revised RPN (After Mitigation)

Calculates the post-mitigation RPN using updated severity, occurrence, and detection values:

```yaml theme={null}
formulas:
  commonRpnNew: "function(info){ var value = info.item['occNew']*info.item['detNew']*info.item['sevNew']; return value?value:null; }"
```

### RPN with Cell Decorator

Combine the RPN formula with conditional formatting to color-code risk levels:

```yaml theme={null}
formulas:
  commonRpn: "function(info){ var value = info.item['occ']*info.item['det']*info.item['sev']; return value?value:null;}"
cellDecorators:
  rpn: "function(info){ var val = info.value; $(info.cell).toggleClass('boldCol', true ); $(info.cell).toggleClass('rpn1', val>0 && val <= 150 ); $(info.cell).toggleClass('rpn2', val > 150 && val <= 250); $(info.cell).toggleClass('rpn3', val > 250);}"
styles:
  ".boldCol": "{font-weight:600;}"
  ".rpn1": "{background-color: #eaf5e9 !important;color: #1d5f20 !important;}"
  ".rpn2": "{background-color: #fff3d2 !important; color: #735602 !important;}"
  ".rpn3": "{background-color: #f8eae7 !important;color: #ab1c00 !important;}"
```

RPN threshold summary:

| CSS Class | Range      | Color                               | Risk Level |
| --------- | ---------- | ----------------------------------- | ---------- |
| `rpn1`    | 1 -- 150   | Green background, dark green text   | Low        |
| `rpn2`    | 151 -- 250 | Yellow background, dark yellow text | Medium     |
| `rpn3`    | > 250      | Red background, dark red text       | High       |

## Risk Matrix (HARA / Action Priority)

### Severity-Probability Risk Level

Implements a risk acceptance matrix using severity and probability to determine acceptability:

```yaml theme={null}
formulas:
  riskValue: "function(info){ var sev = info.item['severity']; var prob = info.item['probability']; if(!sev || !prob) return null; if(sev >= 8 && prob >= 6) return 'Unacceptable'; if(sev >= 5 && prob >= 4) return 'Further Investigation'; return 'Acceptable'; }"
```

<Frame>
  <img src="https://mintcdn.com/none-17b4493f/yWl5nA2D0IzEnZC1/risksheet/diagrams/reference/formulas/formula-examples/diagram-1.svg?fit=max&auto=format&n=yWl5nA2D0IzEnZC1&q=85&s=d6b0d76a78aa5b144074fe03b2bcbfbd" alt="diagram" style={{ maxWidth: "400px", width: "100%" }} width="400" height="310" data-path="risksheet/diagrams/reference/formulas/formula-examples/diagram-1.svg" />
</Frame>

### HARA Risk Level with ASIL Mapping

For ISO 26262 HARA (Hazard Analysis and Risk Assessment) workflows:

```yaml theme={null}
formulas:
  asilLevel: "function(info){ var s = info.item['severity']; var e = info.item['exposure']; var c = info.item['controllability']; if(!s || !e || !c) return null; var score = s + e + c; if(score >= 9) return 'ASIL D'; if(score >= 7) return 'ASIL C'; if(score >= 5) return 'ASIL B'; if(score >= 3) return 'ASIL A'; return 'QM'; }"
```

## Auto-Generated Titles

### Title from Hazardous Situation and Harm

Generates a work item title by combining related fields. Recommended best practice for FMEA (Failure Mode and Effects Analysis) workflows to prevent items without titles:

```yaml theme={null}
formulas:
  autoTitle: "function(info){ var h = info.item['hazardousSituation']||''; var harm = info.item['harm']||''; if(!h && !harm) return null; return h + ' - ' + harm; }"
```

<Tip title="Keep Title Column Visible">
  If the `title` column uses a formula, keep it visible during item creation. Formula columns do not execute when hidden, which causes incorrect titles on newly created work items.
</Tip>

## Cross-Row Aggregation

### Unique Values from Child Items

Available since v24.9.1

Collects unique enum values from downstream risk items into the parent process step row:

```yaml theme={null}
formulas:
  uniqueChars: "function(info){ var rows = risksheet.ds.getMasterRowsByColumnValue('parentId', info.item['parentId']); var vals = []; for(var i=0; i<rows.length; i++){ var v = rows[i]['processChar']; if(v && vals.indexOf(v)===-1) vals.push(v); } return vals.length ? vals.join(', ') : null; }"
```

### Sum Across Child Items

Aggregates numeric values from child risk items:

```yaml theme={null}
formulas:
  totalRisk: "function(info){ var rows = risksheet.ds.getMasterRowsByColumnValue('parentId', info.item['parentId']); var total = 0; for(var i=0; i<rows.length; i++){ total += rows[i]['riskScore']||0; } return total > 0 ? total : null; }"
```

## Field Combination

### Linked Item Fields in One Column

Combines ID and title from a linked item into a single cell:

```yaml theme={null}
formulas:
  combinedLink: "function(info){ var id = info.item['linkedId']||''; var title = info.item['linkedTitle']||''; if(!id) return null; return id + ': ' + title; }"
```

## Conditional Read-Only via cellDecorators

Use `systemReadOnlyFields` in a cell decorator to make columns conditionally read-only based on an enum value:

```yaml theme={null}
cellDecorators:
  conditionalLock: "function(info){ if(info.item['approvalStatus'] === 'approved'){ info.item.systemReadOnlyFields = (info.item.systemReadOnlyFields || '') + '|severity||occurrence||detection|'; } }"
```

## Row Header Styling with Formula Values

Apply conditional styling to row headers based on the revised RPN (Risk Priority Number):

```yaml theme={null}
headers:
  rowHeader:
    renderer: rowHeaderRpnNew
cellDecorators:
  rowHeaderRpnNew: "function(info){ var val = info.item['rpnNew']; $(info.cell).toggleClass('rpn1', val>0 && val <= 150 ); $(info.cell).toggleClass('rpn2', val>0 && val > 150 && val <= 250); $(info.cell).toggleClass('rpn3', val>0 && val > 250);}"
```

## Top Panel Function for Dynamic Risk Matrix

Define a risk matrix in the top panel that reads from external configuration, avoiding hardcoded values in each project's sheet configuration:

```velocity theme={null}
## risksheetTopPanel.vm
#set($matrixData = $doc.getOldApi().getValue('riskMatrixConfig'))
<script>
  var riskMatrix = JSON.parse('$matrixData');
  function lookupRisk(info) {
    var key = info.item['severity'] + '_' + info.item['probability'];
    return riskMatrix[key] || 'Not Evaluated';
  }
</script>
```

```yaml theme={null}
formulas:
  riskFromMatrix: "function(info){ return lookupRisk(info); }"
```

## Complete FMEA Configuration

A full working example combining RPN formulas, risk parameter ratings, and conditional formatting:

```yaml theme={null}
formulas:
  commonRpn: "function(info){ var value = info.item['occ']*info.item['det']*info.item['sev']; return value?value:null;}"
  commonRpnNew: "function(info){ var value = info.item['occNew']*info.item['detNew']*info.item['sevNew']; return value?value:null; }"
cellDecorators:
  rpn: "function(info){ var val = info.value; $(info.cell).toggleClass('boldCol', true); $(info.cell).toggleClass('rpn1', val>0 && val<=150); $(info.cell).toggleClass('rpn2', val>150 && val<=250); $(info.cell).toggleClass('rpn3', val>250); }"
  rowHeaderRpnNew: "function(info){ var val = info.item['rpnNew']; $(info.cell).toggleClass('rpn1', val>0 && val<=150); $(info.cell).toggleClass('rpn2', val>0 && val>150 && val<=250); $(info.cell).toggleClass('rpn3', val>0 && val>250); }"
styles:
  ".boldCol": "{font-weight:600;}"
  ".rpn1": "{background-color: #eaf5e9 !important;color: #1d5f20 !important;}"
  ".rpn2": "{background-color: #fff3d2 !important;color: #735602 !important;}"
  ".rpn3": "{background-color: #f8eae7 !important;color: #ab1c00 !important;}"
headers:
  rowHeader:
    renderer: rowHeaderRpnNew
  columnHeader:
    height: 32
  columnGroupHeader:
    height: 32
columns:
  - id: sev
    header: S
    type: rating:severity
    headerGroup: Initial Risk
  - id: occ
    header: O
    type: rating:occurrence
    headerGroup: Initial Risk
  - id: det
    header: D
    type: rating:detection
    headerGroup: Initial Risk
  - id: rpn
    header: RPN
    type: int
    formula: commonRpn
    cellRenderer: rpn
    headerGroup: Initial Risk
  - id: sevNew
    header: S
    type: rating:severity
    headerGroup: Revised Risk
  - id: occNew
    header: O
    type: rating:occurrence
    headerGroup: Revised Risk
  - id: detNew
    header: D
    type: rating:detection
    headerGroup: Revised Risk
  - id: rpnNew
    header: RPN
    type: int
    formula: commonRpnNew
    cellRenderer: rpn
    headerGroup: Revised Risk
```

## Related Pages

* [Formula Syntax](/risksheet/reference/formulas/formula-syntax) -- function signature and execution behavior
* [Formula Functions](/risksheet/reference/formulas/formula-functions) -- helper functions and data access patterns
* [Cell Decorators](/risksheet/reference/styling/cell-decorators) -- conditional formatting with decorators
* [CSS Classes](/risksheet/reference/styling/css-classes) -- custom style definitions
* [Top Panel Template](/risksheet/reference/templates/top-panel-template) -- advanced function hosting

<LastReviewed date="2026-06-24" />
