Scenario analysis with Power BI
How to compare two or even more scenarios in Power BI ? At the moment there is no build-in feature in Power BI that allows you to dynamically compare scenarios, but with DAX this is no problem. In this blog post I will show you how to set up your data model and the formulars for this task.
First of all we need some data, I use generic data here, but the example can easyly be converted to your data. The data in this example looks like this: Every row is one Product at one date for one scenario with the coressponding value. As you can see in the screenshot there are 2 products and 3 scenarios for each product. The formulars shown below also work for more products or scenarios. The story behind the data could be you that you are the analyst and have to compare three scenarios, which show the future develeopment of the sales amount for the upcoming year.
Let's start by creating a visual that helps us to see the difference between the three scenarios. So create a line chart and put the 'Date' on the axis, the' Scenario' on the legend and 'Value' on value. With a simple slicer on the top for 'Product' we can now simply select either one of the products or both together. Out of the box you can now compare the different scenarios with each other. Click on the GIF below to see it in action.
From the visual above, we can see that S1 and S2 appear to move up and down around an unknown expected value. S3 seems to linearly increase every month. So maybe the truth lies in the combination of all three scenarios. For example if I'm a little bit risk avers I might be intereset in the minimal sales amount of all scenarios. Or if I am an optimstic guy, I can look for the maximal sales amount of all three scenarios combined. This can be easily solved with DAX by using this formulars.
- Max Curve =SUMX ( 'Scenario Long'; MAX ( 'Scenario Long'[Value] ) )
- AverageCurve =SUMX ( 'Scenario Long'; AVERAGE ( 'Scenario Long'[Value] ) )
- MinCurve =SUMX ( 'Scenario Long'; MIN ( 'Scenario Long'[Value] ) )
Dynamic scenario comparison
Many users want to be able to dynamically compare scenarios. To do this in Power BI you need a little trick in DAX. The simplest way to do this is to use a parameter table. Parameter tables are tables independent of the actual data model, which are only integrated via measures. The parameter table only contains the unique names of our scenarios. The easiet way to create parameter tables in our case is to create 2 custom tables in the model by using the distinct function.
- Base =DISTINCT ( 'Scenario Long'[Scenario] )
- Reference =DISTINCT ( 'Scenario Long'[Scenario] )
We now create measures that check if one of the parameter tables is filtered. The measure will then only sum up the corresponding scenario from the content table (Scenario Long). On SQL BI their is a very good explanation how to integrate a parameter table into a measure.
- Base Scenario =CALCULATE (
- SUM ( 'Scenario Long'[Value] );
- TREATAS ( VALUES ( Base[B_Scenario] ); 'Scenario Long'[Scenario] ))
- ReferenceScenario =CALCULATE (
- SUM ( 'Scenario Long'[Value] );
- TREATAS ( VALUES ( Reference[R_Scenario] ); 'Scenario Long'[Scenario] ))
With a simple subtraction we can calculate the difference between both scenarios. Click on the GIF below to see everything in action.
- Dif. between Reference and Base = [Reference Scenario] - [Base Scenario]
So with all this in place we can now easily compare two scenarios with each other. I puplished this report example, you can view it here: Compare two Scenarios. I think this use case is another example how powerful the data modeling engine behind Power BI is and how easily it can be used to extend the technical possibilities. I hope you find this helpful.