Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
I had a customer ask to create a check box selector for the key figures shown in a crosstab during runtime. Previously, they had to scroll across the screen to view all of their key figures, which they found time consuming and annoying- especially if they wanted to compare two numbers that weren't next to each other in the regular, static layout.

Now they can select the check boxes for the key figures that they want to see at one time and hit "go" to have them show up in their crosstab, all during runtime. I also hard coded the items into the check box group and pre-selected the measures that show up in the initial view of the crosstab.

It took me a while to figure this out, so hopefully my time lost can be your time gained! I used a check box group and button scripting, as seen below.




To add this feature to your own dashboard:

1. Create a check box group (or any other multi-select option) with the names you want to use for each measure column.

2. Place a crosstab in the dashboard and assign it a data source.

3. Either create a button with an On Click code after selecting the desired columns (preferred for performance) or add it straight to the On Click of the check box group.

4. Add the On Click code (copy and paste from below), and replace anything in <> with your own column names/measures/IDs, etc (remove the <>).

//create the variable to hold the string

var string = "";

//get the array of selected texts from the text box groups and run a loop on each element

<CHECKBOXGROUP>.getSelectedTexts().forEach(function(element, index) {

//run an if statement on each selected element that checks if it matches the column names in your check box group. If it matches, the ID of that measure will be added to the string variable with a comma. Add an if statement for each member of your check box group.

if(element == "<ColName1>"){
string = string + "<measure_ID1>" + ",";
} else if (element == "<ColName2>"){
string = string + "<measure_ID2>" + ",";
} else if (element == "<ColName3>"){
string = string + "<measure_ID3>" + ",";

//use the substring function to remove the comma at the end of the string

var rmvComma = string.substring(0,string.length-1);

//create an array variable using the split function to separate array members by the commas

var array = rmvComma.split(",");

//add a filter to the data source that is assigned to your crosstab, adding the measures dimension ID and then the array variable

<DATA_SOURCE>.setFilter("<Measures_Dimension_ID>", array);


Once these pieces are in place, run the dashboard and test it out. You should be able to select the columns in your checkbox group that you want to see in your crosstab, click your "go" button, and watch the script go to work!


Happy coding!