cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAC Scripting Function Top N Filter

StefWig
Explorer
0 Likes
347

Hello everyone,

for my story I implemented a dynamic measure change via a switch for three of my charts. One of them is as standard equipped with a top n filter. However, when i flip the switch and the new measures are shown the filter is being removed.

Do you know if there is a function to enable the filter again afterwards?

Thank you all in advance!

var measuresStandard2 = ["", "", "", ""];
var measuresAlternative2 = ["", "", "", ""];

var measuresStandard3 = [""];
var measuresAlternative3 = [""];

var isSwitchOn = this.isOn();

if (isSwitchOn) {
    // Chart 1
    for (var i = 0; i < measuresStandard1.length; i++) { Chart_1.removeMeasure(measuresStandard1[i], Feed.ValueAxis); }
    for (var j = 0; j < measuresAlternative1.length; j++) { Chart_1.addMeasure(measuresAlternative1[j], Feed.ValueAxis); }

    // Chart 2
    for (var k = 0; k < measuresStandard2.length; k++) { Chart_2.removeMeasure(measuresStandard2[k], Feed.ValueAxis); }
    for (var l = 0; l < measuresAlternative2.length; l++) { Chart_2.addMeasure(measuresAlternative2[l], Feed.ValueAxis); }

    // Chart 3
    for (var m3 = 0; m3 < measuresStandard3.length; m3++) { Chart_3.removeMeasure(measuresStandard3[m3], Feed.ValueAxis); }
    for (var n3 = 0; n3 < measuresAlternative3.length; n3++) { Chart_3.addMeasure(measuresAlternative3[n3], Feed.ValueAxis); }

} else {
    // Chart 1
    for (var m = 0; m < measuresAlternative1.length; m++) { Chart_1.removeMeasure(measuresAlternative1[m], Feed.ValueAxis); }
    for (var n = 0; n < measuresStandard1.length; n++) { Chart_1.addMeasure(measuresStandard1[n], Feed.ValueAxis); }

    // Chart 2
    for (var o = 0; o < measuresAlternative2.length; o++) { Chart_2.removeMeasure(measuresAlternative2[o], Feed.ValueAxis); }
    for (var p = 0; p < measuresStandard2.length; p++) { Chart_2.addMeasure(measuresStandard2[p], Feed.ValueAxis); }

    // Chart 3
    for (var o3 = 0; o3 < measuresAlternative3.length; o3++) { Chart_3.removeMeasure(measuresAlternative3[o3], Feed.ValueAxis); }
    for (var p3 = 0; p3 < measuresStandard3.length; p3++) { Chart_3.addMeasure(measuresStandard3[p3], Feed.ValueAxis); }
}

 

View Entire Topic
N1kh1l
Active Contributor
0 Likes

@StefWig 

You could try the rankBY API. Just type Chart_1.rankBy({}); Inside the curly braces press Ctrl Space and it will allow to populate options as below.

https://help.sap.com/doc/1639cb9ccaa54b2592224df577abe822/release/en-US/index.html#Chart_MrankBy

//Top 5
Chart_1.rankBy({rankOrder:RankOrder.Top,structureMember:"[Account_BestRunJ_sold].[parentId].&[Gross_Margin]",value:5});

N1kh1l_0-1776957293023.png

 

 

Hope this helps !

Nikhil

StefWig
Explorer
0 Likes
You are the best. Thank you so much!
Insan28
Explorer
0 Likes
Hi Nikhil ..thanks a lot for your solution. Please can you also help if there is dynamic dimension selection via input control for the table and want to cluster Top N and others based on the selected dimension
N1kh1l
Active Contributor
0 Likes
Read the input control selected member and pass it above example in place of accounts in structure member option