How to use the removeDimensionFilter() and setDimensionFilter() API’s with SAP Analytics Designer
The removeDimensionFilter() and setDimensionFilter() API’s are used to filter either on members or properties of a dimension on tables and charts with SAP Analytics Cloud Analytics applications.
In this blog we used an example that sets filters from dropdowns and checkbox groups on 6 tables and 26 charts using one loop and only refreshing the widget when visible, hence, making it a best practice example, keeping the analytics application fast and responsive despite loading massive amounts of data.
OnInitialization
After setting up the dropdowns and checkbox groups and writing all the fx code onInitialization for the dimensions in dropdowns needed in the report;
Example:
Create all the tables and charts
Create and detail all the tables and charts needed in your reporting dashboard, then make sure to chose the Refresh active Widgets Only from the Data Refresh on the tables and charts Builder on each.
Script Variables
Create all the Script Variables for the aforementioned filtering widgets (dropdowns and checkbox groups) as shown below:
In our analytics application we used 3 dropdowns and 3 checkbox groups to filter tables and charts from 6 different dimensions; Entity, Currency, Intercompany using dropdowns; Category (version), Audit Trail, and flow using checkbox groups.
Create a Script Variable for each dimension; since they are reusable elements that store a value of a certain type. Set them all to Type string, and activate the Set As an Array toggle button.
Script Objects
Then create a Script Objects; call it Utils, and add a Script Function; call it updateWidgets, with a Return Type void, then add an Argument call it source, and set its Type to string as shown below.
Using the removeDimensionFilter() and setDimensionFilter() API’s to apply filters on widgets sometimes will have special requirements.
The Analytics Application we used in this blog has a special filtering requirement, for example, we have one flow checkbox group filtering only on Balance sheet tabs as a property of a dimension. And the Intercompany dropdown filter only on intercompany related tabs.
We will share in another blog how to hide and show filters depending on tab selections; which will take your filtering capabilities to a higher level.
Script Function fx
On the Script Function fx we created a table list and a chart list that need to be updated in arrays. The arrays for tables and charts need to be separate, since SAC can’t have arrays of mixed widget types. These 2 arrays are used at the end of the script to update widgets once with appropriate actions.
After creating the tables and charts arrays, we use the removeDimensionsFilter and setDimensionsFilter APIs. The for statement will loop through all tables and charts once, and the if statement will update filters appropriately.
Now the user is able to remove and set dimension filters from widgets on multiple tables and charts.