cancel
Showing results for 
Search instead for 
Did you mean: 
TriAnthony
Sisense Team Member
Sisense Team Member

Input Parameters using BloX for What-If Analysis

This is an alternative to the paid or community Input Parameter plugins.

This new BloX Input Parameter custom action:

  • supports multiple levers (input parameters) with just one Apply button
  • supports all widget types
  • remembers previous selections even after refreshing/closing the dashboard
  • loops through all widgets so dashboard designers do not have to specify widget IDs in the BloX code. Note: Be mindful of performance when considering this option as this will execute the BloX action on all widgets including those that the input parameters may not necessarily be relevant to.
TriAnthony_0-1720710489881.png 

Input Parameter Implementation

Instructions:
  • Import the example dashboard attached below. Before importing the file, change the file extension from .txt to .dash. Make sure that you still have the Sample ECommerce Elasticube for this dashboard to properly display the data.
  • Open the BloX Lever Configuration widget, then add the custom action given below to your Sisense environment.
    • Go to the Actions tab, click the three-dot menu, then click Create Action.
    • Copy the custom action code from below and paste it into your BloX custom action editor.
    • Give this name for the action: ParameterSwap_V2_AllWidgets. You can also use a different name, but make sure the name of the action matches with the name referenced in the BloX code.
    • Click Next, then Create.
  • Click the Apply button to close the widget.
  • Enter values to the levers and click Apply. The number on the widgets is now recalculated based on your input.

There are three input parameters in this example. To add another input parameter:

  • In the BloX code of the Lever Configuration widget, modify the number of input parameters in the BloX code under the paramsToModify parameter. For example, if you need 4 input parameters (levers), update the value to 4.
TriAnthony_2-1696346104586.png
  • On the left panel, add the additional swap_levers to the Values panel, i.e. swap_lever4, swap_lever5, etc. You can assign any arbitrary hard-coded number to these swap levers.

TriAnthony_6-1696346401759.png

  • To add the input box to the widget, copy one of the column elements then add it to the BloX code. Modify the id parameter to selectVal<lever number>, e.g. if this is the fourth lever, the id should be selectVal4. Similarly, modify the value parameter to match the swap_lever name you added in the previous step, e.g. [swap_lever4]. Update the title text as well and give it a meaningful description.
        
TriAnthony_8-1696347177772.png
  • Save the widget by clicking the Apply button.
  • Add the additional levers to your widget formulas as needed so that they get recalculated when you enter the input values.

Input Parameter BloX action:

 

//initialize variables
var swapParam = [];

//create an array of swap_levers
for (d = 0; d < payload.data.paramsToModify; d++) {
    swapParam[d] = "swap_lever" + (d + 1);
}

//loop through each of the specified widgets
payload.widget.dashboard.widgets.$$widgets
    .forEach(function (widget) {

        //loop through each panel in the widget
        //exclude the filter panel (last panel)
        for (p = 0; p < widget.metadata.panels.length - 1; p++) {

            //loop through each item in the panel
            for (i = 0; i < widget.metadata.panels[p].items.length; i++) {

                //check if the panel item contains context (i.e. a formula)
                if (widget.metadata.panels[p].items[i].jaql.context != undefined) {
                    var queryContext = widget.metadata.panels[p].items[i].jaql.context;

                    //loop through each context in the item
                    for (let [k, v] of Object.entries(queryContext)) {

                        //loop through each swap_lever
                        for (s = 0; s < swapParam.length; s++) {

                            //check if the formula contains the swap_lever
                            if (v.title == swapParam[s]) {
                                var val = 'selectVal' + (s + 1);

                                //update the formula with the swap_lever value that the user entered
                                v.formula = payload.data[val];
                            }
                        }
                    }
                }
            }
        }

        //apply and save changes to the widget
        widget.changesMade('plugin-BloX', ['metadata'])

        //refresh the widget
        widget.refresh();
    })

 

Resetting to Default Values

The attached dashboard example includes a Reset button to reset the input parameters to pre-set default values. If you do not need this option, you can remove the second action from the BloX code, as shown in the highlighted part of the screenshot below.

TriAnthony_1-1720710919771.png

Instructions to implement the Reset button:

  • Open the BloX Lever Configuration widget, then add the custom action given below to your Sisense environment.
    • Go to the Actions tab, click the three-dot menu, then click Create Action.
    • Copy the custom action code from below and paste it into your BloX custom action editor.
    • Give this name for the action: ParameterSwap_V2_AllWidgets_Reset. You can also use a different name, but make sure the name of the action matches with the name referenced in the BloX code.
    • Click Next, then Create.
  • In the BloX code, update the defaultValues array with your required default values. See screenshot below for reference.
  • There are three input parameters in this example, if you have more/less parameters, update the paramsToModify value to the correct number of parameters that you have. See screenshot below for reference.

TriAnthony_3-1720711347218.png

  • Click the Apply button to close the widget.

Reset Input Parameter BloX action:

 

//initialize variables
var leverValues = payload.data.defaultValues;
var swapParam = [];

//create an array of swap_levers
for (d = 0; d < payload.data.paramsToModify; d++) {
    swapParam[d] = "swap_lever" + (d + 1);
}

//loop through all widgets in the dashboard
payload.widget.dashboard.widgets.$$widgets
    .forEach(function (widget) {

        //loop through each panel in the widget
        //exclude the filter panel (last panel)
        for (p = 0; p < widget.metadata.panels.length - 1; p++) {

            //loop through each item in the panel
            for (i = 0; i < widget.metadata.panels[p].items.length; i++) {

                //check if the panel item contains context (i.e. a formula)
                if (widget.metadata.panels[p].items[i].jaql.context != undefined) {
                    var queryContext = widget.metadata.panels[p].items[i].jaql.context;

                    //loop through each context in the item
                    for (let [k, v] of Object.entries(queryContext)) {

                        //loop through each swap_lever
                        for (s = 0; s < swapParam.length; s++) {

                            //check if the formula contains the swap_lever
                            if (v.title == swapParam[s]) {
                                var val = 'selectVal' + (s + 1);

                                //update the formula with the default value
                                v.formula = leverValues[s];
                            }
                        }
                    }
                }
            }
        }

        //apply and save changes to the widget
        widget.changesMade('plugin-BloX', ['metadata'])

        //refresh the widget
        widget.refresh();
    })

 

We hope this is a helpful article and would love to hear about your experience in the comments! 

Rate this article:
Comments
angupta
7 - Data Storage
7 - Data Storage

Hi,

Thanks for this article

I am able to create it. But as you claim that it will not lose values even after refreshing the page. That is not happening. Can you please help me with that.

 

TriAnthony
Sisense Team Member
Sisense Team Member

Hi @angupta,

Did you add the swap_levers to the BloX widget (see screenshot below)?

In order for the BloX widget to show the last inputted values after a refresh, the swap_levers need to be added to the BloX widget. The swap_levers' values serve as the default values for the input boxes, which will also be updated by the BloX action.

TriAnthony_0-1720464990538.png

If you have added these to the BloX widget and it's still not working, could you send a copy of the dashboard file?

 

angupta
7 - Data Storage
7 - Data Storage

Hi Tri, 
thanks for the response, 

Yes, I have added swap_lever as a formula in BLoX widget. 
I suspect that, we have added the code to add outlier filter on dashboard using the same action in which we are doing this swap_lever value change, maybe that's why it is not fully functional. It is working on the board provided in the post.

 

Toms
7 - Data Storage
7 - Data Storage

Hi @TriAnthony , 

This is working perfectly for creating scenario planners, thanks for sharing this! I was wondering if it was possible to customize the code so that, upon changing any of the filters/metadata, all the values reset to '0'? Or otherwise a reset button?

This would be helpful to have as a visual reminder that with the filters adjusted, so to need the input fields be adjusted to get to your desired insights. Else it may be easy for our customers to dive into certain filter selections while using the wrong input criteria.

angupta
7 - Data Storage
7 - Data Storage

Hi Trie, 

When I am using your BLoX rather than my BLoX for displaying and performing action, it is not refreshing even after refreshing. 

Can you please tell me the reason for this. Does BLoX widget has some hidden settings?


Also, I wanted to know how to create those [swap_lever]. I thought they were shared formulas, but they are working with cubes which don't have [swap_lever] saved as shared formula. 
Thanks

TriAnthony
Sisense Team Member
Sisense Team Member

Hi @Toms,

Thank you for the suggestion! I had actually implemented a Reset button but didn't get a chance to update the article. It's been added now. Hope you find this helpful. Let me know if you have any questions.

Toms
7 - Data Storage
7 - Data Storage

Hi @TriAnthony 

Thanks a bunch for the addition. Very usefull, and I appreciate the quick response!

I had one final suggestion that I was not able to workout on my own. Would it be possible to have input.number visually be presented as a percentage?
I understand that it works as normal through Sisense formatting when calling upon the swap_lever in subsequent widgets/textfields, but the actual input field that can be adjusted will as an example always show 0,02 instead of 2% which can be confusing for our customers.
Would it be possible to set this to a percentage view?

Thanks, 
Tom

Version history
Last update:
‎07-18-2024 09:12 AM
Updated by: