# Risk Matrix

## Download

<https://github.com/glewe/confluence-user-macros/tree/master/src/risk-matrix>

## What is a Risk Matrix ?

<figure><img src="https://2698388676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhxjY6Qy0WDq9YGYRZ50Q%2Fuploads%2FQiNSiwaEOs6xgTMnITmX%2Frisk-matrix.png?alt=media&#x26;token=84f8b627-e8d6-4695-9a38-554d33b5f9b6" alt=""><figcaption></figcaption></figure>

A risk matrix is a table showing the distribution of risks based on their impact and likelihood (probability).

Such a table is organized in rows representing the likelihood, and columns representing the impact (or vice versa). Each cell represents a combination of both and is colored green, yellow or red depending on the severity of its combination. A risk with a heavy impact and a high likelihood is red, low and low leads to green, the in-betweens are yellow.

In order to get the typical coloring pattern as shown on the left, either the rows or columns need to be ordered ascending while the other needs to be ordered descending.

## Pre-Conditions

This macro uses specific Jira custom fields and values in it. You can adjust those to your environment and use case but then you need to adjust the macro accordingly. For the purpose of this documentation I am assuming that the following pre-conditions are met.

1. This macro accesses Jira issues. It is assumed that you have a Jira instance linked to your Confluence instance.
2. It is assumed that you have created an issue type “Risk” in Jira and a project that uses it.
3. It is assumed that you have created a custom field “Impact” in Jira as a single-select list with the following values:
   * 1 – Very low
   * 2 – Low
   * 3 – Medium
   * 4 – High
   * 5 – Very high
4. It is assumed that you have created a custom field “Likelihood” in Jira as a single-select list with the following values:
   * 1 – Rare (<10%)
   * 2 – Unlikely (11-30%)
   * 3 – Possible (31-50%)
   * 4 – Likely (51-80%)
   * 5 – Almost certain (81-99%)

## Filtering your Risks in Jira

The Risk Matrix macro runs a JQL in Jira, to be precise, it runs a different filter for each cell in the table. Let’s look at the one for the upper left cell from the screenshot above:

{% code overflow="wrap" %}

```
project in MYPROJ and issuetype = "Risk" and Likelihood = "5 - Almost certain (81-99%)" and Impact = "1 - Very low"
```

{% endcode %}

As you probably already assumed, you need one query for each combination of Impact and Likelihood. I suggest you run those filters in Jira first to make sure they return a useful result.

## Adding the Jira Macro in Confluence

Try to add such a query on a Confluence page using the Jira macro. Make sure to drop down the Display options at the bottom and select “Total issue count”. That will output just the number of issues that this query returns.

<figure><img src="https://2698388676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhxjY6Qy0WDq9YGYRZ50Q%2Fuploads%2FLCaUvVz2Gj81S3M232vx%2Fjira-macro.png?alt=media&#x26;token=2acde519-e388-4f2c-9994-f4b51d0f0131" alt=""><figcaption></figcaption></figure>

With that, you can already create a static hard-coded risk table on a Confluence page. Create the table and add each Jira macro in its corresponding cell.

## Creating a Risk Matrix User Macro

It is very probable that there are several projects in your Jira instance using the Risk issue type and all those project managers would like to show a risk matrix in Confluence without going through all the manual table and Jira macro stuff. If you are hosting a Server or Data Center version of Confluence yourself, a user macro is the perfect solution.

A user macro allows the user to conveniently enter custom values into a macro dialog and the macro does all the work for you.

The macro in this example allows to enter:

* project key/s for the queries
* issue type for the queries
* font size
* subtitle
* Likelihood string values (assuming five values)
* Impact string values (assuming five values)

<figure><img src="https://2698388676-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhxjY6Qy0WDq9YGYRZ50Q%2Fuploads%2FWCoSaPefJMr0j3Ji50Xv%2Frisk-matrix-configure-macro.png?alt=media&#x26;token=08d4acbf-f22a-4482-b23b-da4b0edd544d" alt=""><figcaption></figcaption></figure>

The macro also adds a little style sheet providing a more saturated red, yellow and green for the cell backgrounds.

I will not go into the details about how to generate Confluence user macros in general. You can find a good documentation here:

<https://confluence.atlassian.com/doc/writing-user-macros-4485.html>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lewe.gitbook.io/confluence-user-macros/risk-matrix.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
