Forum Discussion
How to build Confusion Matrix in Power BI
To build a Confusion Matrix in Power BI using your dataset, we need to determine if the growth or degrowth predictions (Predicted_XM Prior) matched the actual trend observed in the Value column.
Define Growth/Degrowth Categories
Before building the confusion matrix, we need to classify each Actual Value and Predicted Value as Growth (↑) or Degrowth (↓).
You need to create a Calculated Column for Actual Trend
Add a new column in Power BI using DAX to classify whether the actual value increased or decreased compared to the previous month.
Actual_Trend =
VAR Prev_Value =
CALCULATE(
MAX('YourTable'[Value]),
FILTER('YourTable', 'YourTable'[Date] = EDATE(SELECTEDVALUE('YourTable'[Date]), -1))
)
RETURN
IF(Prev_Value < 'YourTable'[Value], "Growth", "Degrowth")
Create a Column for Predicted Trend
For each Predicted_XM Prior, compare it to the previous actual month’s prediction.
Example for Predicted_1M Prior:
Predicted_Trend_1M =
VAR Prev_Predicted =
CALCULATE(
MAX('YourTable'[Predicted_1M Prior]),
FILTER('YourTable', 'YourTable'[Date] = EDATE(SELECTEDVALUE('YourTable'[Date]), -1))
)
RETURN
IF(Prev_Predicted < 'YourTable'[Predicted_1M Prior], "Growth", "Degrowth")
Repeat the same for Predicted_2M Prior, Predicted_3M Prior, etc.
Build the Confusion Matrix
Now, we need to compare the Actual_Trend and Predicted_Trend.
Create a table visual in Power BI.
Add:
Actual_Trend as Rows
Predicted_Trend_1M (or 2M, etc.) as Columns
Count of rows as Values (to show occurrences)
This creates a confusion matrix where:
Diagonal values (True Positive & True Negative) = Correct predictions
Off-diagonal values (False Positive & False Negative) = Incorrect predictions