In the previous blog in this series, we learnt about Scripting APIs. In this blog, let us start with an interesting & custom implementation of Linked Analysis using scripting.
* * *
Linked Analysis
Linked Analysis enables SAP Analytics Cloud story widgets to dynamically interact with each other based on items selected in a widget. However, this feature is not enabled by default in Analytic Applications, where it must be implemented using scripting.
However, there is one upside to this: we can implement Linked Analysis the way we want in Analytic Applications. Note that the out-of-the-box Linked Analysis functionality provided for stories cannot do complex interactions, and it cannot be customized.
Our goal today is to achieve the chart interaction as shown below (as a side exercise, try to implement this in an SAP Analytics Cloud story, and figure out why it cannot be done).

Linked Analysis In Analytic Applications – An Example
There are three charts – Sales by Region, Sales by Category & Sales by Sub-Category.
Any selection in chart 1 (Region) must filter values in chart 2 & 3 (Category & Sub-Category). Any Selection in chart 2 (Category) must only filter values in chart 3 (Sub-Category), without setting any filters for chart 1 (Region).
Following are the steps involved to implement custom Linked Analysis in Analytic Applications.
1. Create the widgets
Here we start with the analytic application shown below, which does not have any implementation yet for Linked Analysis or filtering.
2. Filter for Region Selection
Add the following script to the onSelect() event of the first chart. This adds the selected region as a filter to the Category & Sub-Category charts.
var region_sel = Chart_Region.getSelection();
for ( var i=0; i < region_sel.length; i++ ) {
if ( region_sel[i].dimensionId === “Region” ) {
Chart_Category.getDataSource().setDimensionFilter ( “Region”, region_sel[i].id );
Chart_SubCategory.getDataSource().setDimensionFilter ( “Region”, region_sel[i].id );
}
}
Note that the onSelect() function does not support selection of multiple values as of now.
3. Filter for Category Selection
Add the following script to the onSelect() event of the second chart to filter category in the third chart.
var category_sel = Chart_Category.getSelection();
for ( var i=0; i < category_sel.length; i++ ) {
if ( category_sel[i].dimensionId === “Category” ) {
Chart_SubCategory.getDataSource().setDimensionFilter ( “Category”, category_sel[i].id);
}
}
Note that in this implementation, no filter is set for the first chart (Region). This flexibility allows us to implement Linked Analysis the way we want in Analytic Applications.
4. Add the Reset functionality
To help the user clear all the filters, add a button ‘Reset Filters’ on the top right.
Then in the onSelect() event of the button add the following script to clear the filter values.
Chart_Category.getDataSource().removeDimensionFilter(“Region”);
Chart_SubCategory.getDataSource().removeDimensionFilter(“Region”);
Chart_SubCategory.getDataSource().removeDimensionFilter(“Category”);
* * *
In the subsequent blog we will learn about Dynamically changing Measures and Dimensions in Analytic Application.
Reach out to our team here if you are interested to evaluate if SAP Analytics Cloud is right for you.
Subscribe to our Newsletter
The post SAP Analytics Cloud – Application Design Series: 9 – Linked Analysis using Scripting appeared first on Visual BI Solutions.