Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

I have been looking at many posts in Design Studio, where users are asking to get the maximum value of a date dimension and restrict data in the dashboard for that latest date or month or year from the database.

This is very useful in case of inventory dashboards where the inventory value or count is viewed for only last day or month or may be year (seldom viewed).

I had to come across a similar requirement in my project in case of inventory where client wants to see only the latest month inventory.

Since the month or date or year is dimension and cannot use aggregation of "Max", we need to manually write a script to find out the latest month available in the data and restrict the entire dashboard to that month.

There is a simple way to do this.

First have a data source with the date or month or year dimension for which the max value needs to extracted.

Lets say in my example i want to find latest month, and from the DB i was getting this month in the format "YYYYMM".

I have created a DS with name DS_1 with dimension "Month" and some measure as its mandatory to have one measure in the DS initial view.

Now go the application properties and create a global variable v_LatestMonth as String.

Now go the onStartup events, and write the below code to fetch the latest month.

var months = DS_1.getMembers("Month",<no of months you want to fetch>); //local array months to hold the values from the DS. use a number where all the values are fetched.

var maxValue = 0; // to hold maximum value

months.forEach(function(element, index) {

  if(maxValue < Convert.stringtoInt(element.text)) {

          maxValue = Convert.stringtoInt(element.text);

     }

});

v_LatestMonth = Convert.floattoString(maxValue);


Now  the v_LatestValue will hold the maximum month value.

This can be used in and getData functions or setFilter functions to restrict for the latest month.

6 Comments
Labels in this area