Skip to Content
Product Information
Author's profile photo Fabien AUBERT

SAP Analytics Cloud sample content : What-if scenario

What-if scenario is a common use case in the analytics world.  With SAP Analytics Cloud you get the perfect solution to handle this scenario. To illustrate this, my colleague Nick Verhoeven and I have created a guided application released in the SAC sample content. In this blog I will explain how to build the application. Find the functional explanation from my colleague here.

The application is composed of 4 tabs. In the first one we only have a text explaining how to use the application.


Create Scenario Tab

In the 2nd tab “Create Scenario” a user can select a planning source version and create a new version based on the source version.

The available source versions are retrieved by using the following code in the “onInitialization” event

var versions = Table_1.getDataSource().getMembers("Version");
while (versions.length>0)
var value = versions.pop();

Note that Table_1 is not present in the Tab2 but in Tab3. The Table_1 contains the “Version” dimension in the column feed.
Once the version is selected the user gives a name to the new version and creates it.

So first we create a private version with the given name:

var key = Dropdown_3.getSelectedText();
var text = Dropdown_3.getSelectedKey();
var name = InputField_1.getValue();
var res = Table_1.getPlanning().getPublicVersion(key).copy(name,PlanningCopyOption.AllData,PlanningCategory.Forecast);

Then we publish this private version:

var bool = Table_1.getPlanning().getPrivateVersion(name).publishAs(name,PlanningCategory.Forecast);

In the 3rd tab we have tables and a chart that show the “Account” dimension for a version. As we want to see the values for the new created version and the source version, we filter these widgets:

var id = Table_1.getPlanning().getPublicVersion(name).getId();

Finally, we are redirected to the 3rd tab.

Run Scenario Tab

This tab contains a lot of elements. At the top right we have a table containing the different drivers which already exist and which Account they influence. A user can add a new driver by clicking on the “Add driver button”. By doing so he will be prompted (popup component) to provide information regarding the new driver: Description, Impact in %, From Date, To Date and Influence Account. By clicking on the ok button, a new driver will be added in the table.


In term of code, it corresponds first to add a new member in the model for the “Drivers” dimension. For that we create a Planning Model’s technical component called “Model”.
From the popup we retrieve the values entered for the Description, From Date, To Date and Influence Account in order to create a new PlanningModelMember object. With the createMembers() method the new member is added to the SAC model.

Member = {id:ID.getValue(),
			properties:{FromDate: result1,
					   ToDate: result2,
var result = Model.createMembers("Drivers", Member);

To add this new member in the table we use the following code

var selection = {
	"Drivers": ID.getValue() ,
	"Version": "public."+InputField_1.getValue()
var test = Table_2.getPlanning().setUserInput(selection, InputField_2.getValue());

var ds = Table_2.getDataSource();

Once the driver has been created, a user can run a data action to calculate the impact on the influence account. Without going into full detail on Data Actions, the Analytics Designer is able to call below data action. The action is filtering the accounts to influence based on the driver dimension with the created drivers. It will multiply the account with the entered driver values within the maintained dates.”

To execute the data action we use the following code in the application

DataAction_1.setParameterValue('TargetVersion', ScenarioVersionId);

Where the ScenarioVersionID is the id of the new version.

Compare Scenario Tab

In the last tab we compare the source scenario with the new scenario.

The result is display in a table. From this table we can open the navigation panel to explore more details with the following code:


Or we can jump to a SAP Analytics Cloud story. When the user clicks on the ” Open Formatted Report” button it opens a popup.

The user publishes the version that has been impacted in the previous tab and selects the versions he wants to compare.

var str ="[" + "\"" + key + "\",";
var values = CheckboxGroup_1.getSelectedKeys();
for (var i = 0 ; i < values.length; i++)
if (i===values.length - 1)
str = str  + "\"" +values[i] + "\"";
str = str  + "\"" +values[i] + "\",";
str = str + "]";
NavigationUtils.openStory("7CD022064D158FDA3FA2F0EA7E0FFF24", "b7e51a0e-4d62-4592-b4e7-66843fa6af41", 

Where the “str” string corresponds to the versions selected. To jump to the story we use the openStory() method for which we pass different parameters (see the code).

In conclusion we were able to see that with the Analytics Designer capability in SAP Analytics Cloud, you can create a What-if application on top of a planning model. I hope you enjoy this blog and stay tuned for more blogs on this topic!


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Prathamesh Acharya
      Prathamesh Acharya

      Very good idea, am sure it will resonate with lot of users

      Author's profile photo Alexander Knight
      Alexander Knight


      I've looked for this content on my system and cannot find it, do you have a precise name and location?

      Also, would the same be possible in a story, to make it even more accessible to users, I'd value your opinion on that.

      Kind regards


      Alexander Knight