Input Parameters using BloX for What-If Analysis
//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!
12 comments
Ido Darnell
·1 year agoThank you TriAnthony this is a super powerful implementation of blox!
Great workaround using Blox for input parameters — it’s always impressive to see how far you can push blox capabilities with some clever scripting.
For those looking for a no-code alternative, we’ve been maintaining a fully supported Input Parameters plugin for the past 4 years. It’s part of our broader effort to simplify self-service analytics and comes with a UI for design, built-in logic for advanced filtering, dynamic thresholds, and even support for string comparisons and parameter queries directly from the model (useful for left joins and similar cases). From reading through this thread above I am confident the plugin can answer all the requirements here.
It's designed to reduce the amount of custom code and ongoing maintenance, and many Sisense users have adopted it as a scalable option. You can read more about it and how it fits into our self-service PowerUps here:
🔗 https://www.qbeeq.io/post/predictive-analysis-for-self-service-analytics
🔗 https://www.qbeeq.io/post/how-to-extend-self-service-analytics-in-sisense
Happy to chat or share more if helpful.
We're always here to help
Ido from QBeeQ
QBeeQ - Gold Sisense Partner
info@qbeeq.io
Feel free to subscribe to our newsletter to stay up to date with the latest QBeeQ news!
Rafael Ferreira
·1 year agoTriAnthony DRay I am trying to understand how the Swapper_level1, swapper_level2, etc are being set into place? Is this in the data model? or this set within the BloX dashboard?
Tri Anthony
OP1 year agoHi Astroraf They are created in the formula editor and can be reused in widgets. They are essentially hard coded numbers saved as starred formulas. The video linked below shows how the levers are created. Please let me know if you have any follow-up questions.
Setting Up Swap Levers.mov
-Tri
DRay
·1 year agoHi Astroraf,
Did Tri provide the answer you need?
HQ_Dev_Prod
·1 year agoHello,
Are you able to help me with solving this.
I was able to use the editor and create the custom action.
I'm trying to figure out how to use the value to calculate a new value. I currently have Price. But I want to use this field to calculate what would happen if price increased by 10%.
Once I have the value, apply action, how do I use this in another widget? Such as a table that shows my the price per material. I have columns Material, Current price, New price. For New price I want to use the value of 10 > Apply it as a 10% price increase to Current price.
Thank you for any help!
Tom Suddaby
·1 year agoHi 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
Tri Anthony
OP2 years agoHi 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.
Animesh Gupta
·2 years agoHi 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
Tom Suddaby
·2 years agoHi 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.
Animesh Gupta
·2 years agoHi 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.
Tri Anthony
OP2 years agoHi 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.
If you have added these to the BloX widget and it's still not working, could you send a copy of the dashboard file?
Animesh Gupta
·2 years agoHi,
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.