cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to create Mandatory Variable at Story level in SAP Analytics Cloud

Sumalini
Participant
0 Kudos
794

I have a requirement to create variables at Story level, when the user opens up/refresh the story, he/she has to see the variable prompt with Mandatory and Optional variables to enter values.

When i try to create a variable, i can see the below.

Sumalini_0-1731008373556.png

I can create variables at Model level but unable to create a Story Level.

I searched everywhere, but no luck, Could someone please help me?

View Entire Topic
DenisT
Explorer

Hi @Sumalini,

variables depend on the type of model you´re using. Let´s assume you have a BW live connection: Here you simply define the variable in the BW query and set it to mandatory. If you then use this model in a story, you´ll get a variable pop-up as designer and are able to define, if you want to set a fixed value or show the pop-up for every user.

Based on your question, I guess you´re using an import model.I´d personally not use variables for your case, but I´ll describe it anyways below. But first here´s an option I do prefer to do (which does require scripting):

  • On your first page you do set all elements to "Data Refresh: Always pause"
  • Additionally set up an "OnInitialization" Event. This event opens a page pop-up (attention: story pop-ups can´t be always used in the OnInitialization event, since the pop-up information may not be loaded yet. Since I did not have this issue with page pop-ups, I currently stick to them).
  • The pop-up includes the filter you require. If you do require some mandatory filtering, you might want to add a check in your "Pup-up close"-button, if the filtering is OK.
  • If this filter should be used for the whole story, you could either use scripting to set story filters or save the selected values in script variables and use them in the "onActive" method for each page to look up the filters and set them by script per page.
  • Of course you need to set all elements to "Data Refresh: Always refresh" again by script when closing the popup.

Anyways: Here´s the info about model variables:

As soon as you create a model variable in the model - and use this model in your story, of course - you´ll see the option to set this variable:

DenisT_1-1731056399182.png

But please keep in mind, that - beside switching the value of the variable - you can´t really do anything with the variable in the story.

Let´s assume you have model with the dimensions "Date" and  "TestDimension" and the measure "Value". You can now set up a variable like this:

DenisT_2-1731056611008.png

This variable can then be used in a calculated measure within the model:

DenisT_3-1731056663086.png

If you upload the following data:

DateTestDimensionValue
01.01.2024A1
01.02.2024B2
01.03.2024C4
01.04.2024A8
01.05.2024B16
01.06.2024C32
01.07.2024A64
01.08.2024B128
01.09.2024C256
01.10.2024A512
01.11.2024B1024
01.12.2024C2048

 and use the model data in the story, the result will be:

DenisT_4-1731057046636.png

If you now switch the varible value in the story to be, the calculated measure will only show the value of "1170" in the row of TestDimension "B":

DenisT_6-1731059170697.png

When you do add the model to the story, you do get the following pup-up:

DenisT_5-1731057243767.png

So you can decide whether the user should get the pop-up whenever the story is opened.

Please keep in mind, that model variables does not offer any setting for mandatory / optional.

You can at least check the value of the selected variables using a script like:

 

var mv_TestVar1Value = Table_1.getDataSource().getVariableValues("mv_TestVar1");

 

Best regards,
Denis