Skip to Content
Technical Articles
Author's profile photo Prasad Gurla

Linked Analysis – Using SAC Analytic Application

Goal:

Accomplish Linked analysis using analytic application

Context:

In a SAP analytics cloud story, a linked analysis between 2 or more charts can be achieved by using the inbuilt linked analysis feature. This is available as an out of the box functionality with a few options to select like selecting data point filtering and the widget selection that will be affected by the linked analysis.

When using the analytics application designer, this functionality is not available out of the box, but can be built in with some simple coding. This blog will demonstrate the linked analysis building in an analytic application.

Analytic Model:

Build any analytic Model or use an existing one. For the sake of demonstration in this blog, an analytic application was built with a few dimensions, namely, Account, Product Group and Regions. The dimensions also have been populated by master data and some transaction data has been loaded into the model.

Analytics Application:

Create an analytic application with 3 charts on the canvas showing the Key figure (Gross Sales) by Product Group, Regions and a total in a numeric chart as shown below.

Our Goal in the current application will be to accomplish a linked analysis with the chart on the left as a source chart and the charts (both numeric point chart and bar chart) on the right as the targets. A click on the product group bar on the left chart should automatically filter the ones on the right on the selected product group.

Analytic Designer supports the use of script objects. These are a collection of user defined functions which can hold certain functionality or business logic and can take arguments and return objects. It is recommended to use script objects whenever possible as they are re-usable and can be called from any part of the application without the need for repetition of same code. Therefore, it becomes easy to maintain the code as changes in the function can be done in a single place.

Add a new script object called “LinkUtils” (1) and add a function by name “LinkChart2Chart” (2)

Select the function on the outline panel.

  • Define the ReturnType for the function as “void” (3)

Add 3 arguments:

  • “sourceChart” of type Chart (4)

 

  • “targetChart” of type Chart (5)

 

  • “linkDimension” of type string (6)

Inside the “LinkChart2Chart” function, add the following code.

{
	var currentSelection = sourceChart.getSelections();
	   if(currentSelection.length > 0)
		{
		  var selMembers = ArrayUtils.create(Type.string);
			for ( var i=0; i < currentSelection.length; i++ ) 
			  {
				for(var currentDim in currentSelection[i])
				  {
					if (currentDim = linkDimension)
					  {
						selMembers[i] =  currentSelection[i][currentDim];
					  }
				  }
			  }
		  targetChart.getDataSource().setDimensionFilter (currentDim, selMembers);
		}
}

The above code is written in a generic format without any reference to a fixed widget or dimension. Therefore, it can be called from any part of the application code multiple times. Note that the function has the arguments as were defined when creating the function.

The currentSelection variable contains the selections of the sourceChart. The selections are looped over and when we find the linkDimension (that was passed) we get the selected members of that dimension and pass it as a filter to the target chart (using setDimensionFilter function).

In the onSelect event of the product group (source) chart, add the following code.

{
   LinkUtils.LinkChart2Chart(Chart_prodgrp, "ProductGroup", Chart_regions);
   LinkUtils.LinkChart2Chart(Chart_prodgrp, "ProductGroup", Chart_numeric);
}

We call the LinkChart2Chart function from the LinkUtils Object (created previously) and pass the parameters for source and target charts as desired. The dimension to pass is “ProductGroup”. Time to test; please find below a short video showing how the linking is working.

Note: A similar function can be developed if linking to/from table widgets is required. In the current scenario, we have called the function a couple of times for linking, the code can be modified to take target chart  as an array.

Conclusion:

The ability to use linked analysis in an analytic application has been demonstrated. The code was also built in a generic way and using a script object so that it can be re-used without having to duplicate code.

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Henry Banks
      Henry Banks

      Hi, Thank you for this. Much appreciated. Like the demo embedded here too, thx! Cheers, H

      Author's profile photo Regys Mene
      Regys Mene

      Hi, this is great!!! Thank you so much!

      Author's profile photo Flo Wimoe
      Flo Wimoe

      Hey, nice tutorial!

      There's one little problem though. The target chart won't reset after there's nothing selected on the source chart.

      You should add an else and remove the dimension filter there.

      Something like this:

      else{
      	targetChart.getDataSource().removeDimensionFilter(linkDimension);
      }