Input Parameters using BloX for What-If Analysis
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.
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.
- 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.
- 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.
- 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.
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.
- 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!
Updated 07-18-2024
TriAnthony
Admin
Joined November 18, 2021