cancel
Showing results for 
Search instead for 
Did you mean: 

Filtering table measures with a dropdown list

01-07-2025 2:07 PM
Rick05 Explorer
1673 views 2 comments Go to solution
0 Likes
SAP Managed Tags
Labels
dropdown listSAP SAC Filtersscript
Subscribe

SAP Analytics Cloud 

Hi I am trying to filter the measures of a table with a dropdown.
I have followed these two tutorials but it does not work.

Best Practice: Filter Table and Chart Through Dropdown (Single Selection) | SAP Help Portal

33. Filtering table through Dropdown in Analytics Application ( SAP Analytics Cloud) - YouTube

My script is as follows:

OnInitialization:

var measures = Table.getDataSource().getMeasures();
//var datas = Table.getDataSource().getInfo();
// console.log(measures);
 
var selectedKey = "";
if( measures.length > 0){
for (var i=0;i<measures.length;i++){
Dropdown_4.addItem(measures[i].id,measures[i].description);
if (selectedKey === "" && i === 0) {
selectedKey = measures[i].id;
Dropdown_4.setSelectedKey(selectedKey);
console.log(["selectedKey ", selectedKey]);
}
console.log(["CurrentMeasure ", measures]);
}
}
 
Utils.setMeasureFilter(selectedKey);
 
Dropdown:
var selection = Dropdown_4.getSelectedKey();
Utils.setMeasureFilter(Dropdown_4.getSelectedKey());
console.log(selection);
// debugger;
//Table.getDataSource().refreshData();
 
setMeasureFilter (script object):
console.log(selectedId);
Table.getDataSource().removeDimensionFilter("NEWSTOCK");
if (CurrentMeasureFilterSelection !== ""){
Chart_6.removeMember(Feed.ValueAxis, CurrentMeasureFilterSelection);
}
 
Table.getDataSource().setDimensionFilter("NEWSTOCK",selectedId);
Chart_6.addMember(Feed.ValueAxis, selectedId);
 
My scriptobject does have a string argument with selectedId
 
my script variable looks like this:
Rick05_0-1736254601160.png

My dataset name is NEWSTOCK and it has 6 measures.

The chart will change, but keeps on adding measures (I have fixed this in a problem were I only have charts another way). But the table will not change. The measures do appear in the dropdown and seem to be written right in the console.log().

I maybe think the problem lies with the value NEWSTOCK, this is the only point that differs from the tutorial that I see? Does anyone know what I am doing wrong?

Kind regards,

Rick

 

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Yogeshwar_M
Active Participant

Hi @Rick05,

I tried the same scenario filter measures in table I have below measure's as shown in table 

Yogeshwar_M_0-1736267485781.png

2. I used below script on dropdown.

var selectedMeasure = Dropdown_3.getSelectedKey();
if(selectedMeasure ==="Quantity"){
Table_5.getDataSource().setDimensionFilter(Alias.MeasureDimension,["Quantity"]);

}else{

Table_5.getDataSource().setDimensionFilter(Alias.MeasureDimension,["Discount"])
;
Table_5.getDataSource().setDimensionFilter(Alias.MeasureDimension,["Profit"]);
Table_5.getDataSource().setDimensionFilter(Alias.MeasureDimension,["Sale"]);

Yogeshwar_M_1-1736267615008.png

3. Its filter according to measures selection

Yogeshwar_M_2-1736267833982.png

4. If I select Sale it will filter as per Sale's Measure 

Yogeshwar_M_3-1736267941459.png

OR

Same Scenario you can do with "Measure Input Control" you don't need to be write script it will work on both chart and table

Yogeshwar_M_0-1736268631873.png

2. Add Measure Input control and remove other measure's

Yogeshwar_M_1-1736268813897.png

 

Kindly upvote if you find it helpful!

 

 

Thanks

 

Rick05
Explorer
0 Likes

Thanks @Yogeshwar_M ,

This solved my problem, the script to filter measures of a table works.

Kind regards,

Rick

Answers (0)