cancel
Showing results for 
Search instead for 
Did you mean: 

Adding more than 1 measure to the datasource filter in sac script

abdussamad_peera
Participant
0 Kudos

Hello Folks

I am trying to add either a KG measure or LBS measure to the table based on the plant. I have 8 KFs, 4 in KG and 4 in LBS. Certain plants will show the 4 KFs that are in KG and others in LBS. So when the plant A is selected I want to only display 4 KFs in LBS while Plant B will show 4 KFs in KG.

Now I know the dimensionfilter for KFs can add only one KF to the filter in a single statement so the suggestion is to fire 4 statements (one for each KF or loop thru it) but When I add the 4 KFs to the datasource dimension filter only the last KFs shows in the table (not all 4). In this example I am not showing a plant selection but listing only KFs with "KG" in the KF description.

var ds = Table_1.getDataSource();

var dimensions = Alias.MeasureDimension;

var tt = dimensions.length;

for (var i=0; i<tt; i++) {

tt1 = Table_1.getDataSource().getMeasures()[i].description;

if (tt1.includes("KG")) {

ds.setDimensionFilter(Alias.MeasureDimension, Table_1.getDataSource().getMeasures()[i]); }

}

I end up with the very last KF in the table.

Before the script is fired.. at startup.

After the script is run - only the last column shows instead of 4 KFs for KG.

Please advise.

Accepted Solutions (1)

Accepted Solutions (1)

N1kh1l
Active Contributor

apeera

apeeraThe system is doing exactly what your code is asking it to do. When you loop, it runs in a sequence and only the last value in loop variable i will be retained as previous 3 values were set as filters one by one. I think you need to create an array of measures with type KG and then pass that array rather than a single variable. Something like below

var ds = Table_1.getDataSource();
var measures = ArrayUtils.create(Type.MeasureInfo);

var member = ds.getMeasures();
for (var i=0; i<member.length; i++) {

var memberId = member[i].id;
var memberDescription = member[i].description;
if (memberDescription.includes("KG"))
	{

		measures.push({id: memberId, description: memberDescription});
	}
}
console.log(measures); // just to see list of measures. can be removed later

ds.setDimensionFilter(Alias.MeasureDimension, measures);

Br.

Nikhil

abdussamad_peera
Participant
0 Kudos

Perfect! Thanks Nikhil for showing the code!!

Answers (0)