cancel
Showing results for 
Search instead for 
Did you mean: 

How to create loop in Design Studio 1.6

ely_turkenitz
Participant
0 Kudos

Hello experts,

We are currently at SAP Design Studio 1.6 version. We are not using BW so there is no BEX Query Designer.

We are in need to list last 36 months (March 2016, Feb 2016, etc) on a drop down box and depends on the month selected, data will be displayed on dashboard accordingly. We got the latest month and year value from the source query in universe, but when using the Month dimension in DS dropdown, it didn't sort the month value in chronological order but in alphabetical order instead.

Source query result sorted by Seq_Month_Number Desc :

We need the drop-down box  to show the order of the month column.

Is there a way to achieve this in DS?

Thanks in advance for any valuable tip/trick.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use the Seq_Month_Number dimension in your data source and populate the drop down box for month selection. I am not sure whether you have 36 months restricted in your data source already or not. Therefore, try one of the two methods below;

1. If data source only has 36 months restricted already.

var monthSeq = DS_1.getMembers(Seq_Month_Number,100);

//This will return only 36 months even though it is trying to extract 100 members;


var month = DS_1.getMembers(MONTH,1);

var monthMember = month[0];

var monthText = monthMember.internalKey;

dropDownBox.removeAllItems();

monthSeq.forEach(function(element, index) {

     DS_1.setFilter(Seq_Month_Number,element.internalKey);

     month = DS_1.getMembers(MONTH,1);

     monthMember = month[0];

     monthText = monthMember.internalKey;

     dropDownBox.addItem(monthText,monthText);

}


2. If data source only has more than 36 months.


var monthSeq = DS_1.getMembers(Seq_Month_Number,1000);

var monthSeqLength = monthSeq.length - 37;

var month = DS_1.getMembers(MONTH,1);

var monthMember = month[0];

var monthText = monthMember.internalKey;

dropDownBox.removeAllItems();

monthSeq.forEach(function(element, index) {

     if (index > monthSeqLength) {

          DS_1.setFilter(Seq_Month_Number,element.internalKey);

           month = DS_1.getMembers(MONTH,1);

           monthMember = month[0];

          monthText = monthMember.internalKey;

          dropDownBox.addItem(monthText,monthText);

     }

}


Before you try any of the two approach above, make sure in the initial view of the data source the Members for Filtering for MONTH dimension is set to Only Values with Posted Data.


Regards,

Swapnil Koti

Former Member
0 Kudos

HI Swapnil,

Very nice logic . Here i am having doubts

1. var monthSeqLength = monthSeq.length - 37;--> for this is data source having only 36 months so your doing 36-37=-1

so you are creating loop by comparing   if (index > monthSeqLength) so here what is the index value? is index value Zero?

Could you please explain me how did you achieve this logic i tried from my end but still  confused with your logic .if you could explain the logic higly appreciated

Thanks,

Vaurn

Former Member
0 Kudos

Hi,

If your data source has only 36 months then please go with the first option out of the 2. If you have more than 36 then go with the second option where we subtract 36 from the total to get the relative starting point.

So, please try the first option.

Regards,

Swapnil Koti

Former Member
0 Kudos

Hi Swapnil,

I Have more than 36 months . and you mentioned need to do minus with 37?

we need to do with  36 right?

As  am new to design studio . i didnt understand few things from your code

you compared index>monthsq.lenth .so here what us the value of index with what your comparing

and why you took month[0] --. can you explain this

actually explain code how you achieved .

any help highly appreciated

Thanks,

Varun

Former Member
0 Kudos

Hi Varun,

The members are stored in arrays. Index variable specifies the item number in an array and element is the member itself. You can access the first member at index = 0.

Now, since getMembers() returns in ascending order, to select the latest 36 we subtract 37 to get the index of last item in the array to be ignored. Any member with index greater than the index calculated for last item is added to the drop down.

You can further read about arrays here,

Regards,

Swapnil Koti

Answers (2)

Answers (2)

ely_turkenitz
Participant
0 Kudos

Thank you everyone for the feedback. We will give it a try.

Much appreciated.

Karol-K
Advisor
Advisor
0 Kudos

Hi Ely,

you can also take a look at the which will list you all months. If you need to make a loop, you can take the component - it has a method "eaches(...)".

All those components are free and available in the SCN community package.

Karol