Date could be filtered as individual members or list of predefined ranges through input controls in SAC with live models. But there is no direct way to adjust the date range at the runtime/view. By utilising the ability of the range slider element, runtime date range filtering could be performed. Lets look into the steps to successfully implement this functionality.
Range slider is a filter/control element available in both SAC analytical application and new unified story. Either manual(fixed input) or variables(dynamic input) could be fed into the slider data source.
Range slider builder panel
Basic idea: Mapping slider values as a corresponding index values of the date array to create an indirect linear relation
Co-relating slider and array
// Page --> OnInitialization
// Create a date array from the data source
var dateArr = Chart_23.getDataSource().getMembers("2FZODS-CALENDAR_WEEK");
var length_DtArr = dateArr.length;
// Set the Slider maximum value to the length of the Array to match indexing
RangeSlider_Whole.setMaxValue(length_DtArr);
// Initiate dynamic variables for selected range in the slider
ScriptVariable_1=0;
ScriptVariable_2= length_DtArr;
// Get date as an array
var dateArr = Chart_23.getDataSource().getMembers("2FZODS-CALENDAR_WEEK");
// Using slider data as index value for date array
var low = RangeSlider_Whole.getRange().getStartValue();
var high = RangeSlider_Whole.getRange().getEndValue();
// Create a new array with selected range from slider by slicing original date array
var slicedDate = dateArr.slice(low,high);
// Filtering the date range
Chart_23.getDataSource().setDimensionFilter("2FZODS-CALENDAR_WEEK",slicedDate);
// Display text in dynamic text
var start = dateArr.slice(low,low+1);
var End = dateArr.slice(high-1,high);
// start{dtype: memberInfo} converted into String in the below code, As dynamic text accepts string| Int | array of strings not memberInfo dataType
Start_date = start[0].id;
End_date = End[0].id;
Output:
Before filtering
After filtering
In HANA modelling, create a week field by using SQL engine calculated column from the target date field
Calculated column in HANA: SQL Engine
// Get min and max selected value
var low =RangeSlider_1.getRange().getStartValue();
var high=RangeSlider_1.getRange().getEndValue();
// Creating an empty array of type string
var rangeArray =ArrayUtils.create(Type.string);
//Creating a continuous sequence of week between selected range
for(var i=low;i<=high;i++)
{
var j = ConvertUtils.numberToString(i);
rangeArray.push(j);
}
// Filtering the data based on selected number range
Chart_23.getDataSource().setDimensionFilter("2FZODS-WEEK",rangeArray);
By utilising the scripting and the range slider element, The date range filtering was performed dynamically during runtime/view mode. Many such custom requirements would also be possible with the help of inbuilt scripting in SAC Analytical application/ Optimised design story.