Use setDimensionFilter API on Range and Exclude Filters

As an application designer or story developer, you can use script API DataSource.setDimensionFilter() on range filters and exclude filters.

Exclude Filters

You can filter out members from the drill-down with exclude filters. The following examples show the use of exclude filters:
  • In the following example, a single filter value is set for dimension "EMPLOYEE_ID". This keeps only the member with employee ID 230 in the drill-down:
    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {value: "230"});
  • In the following example, a single but excluding filter value is set for dimension "EMPLOYEE_ID". This removes the member with employee ID 230 from the drill-down:
    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {value: "230", exclude: true});
  • In the following example, multiple filter values are set for dimension "EMPLOYEE_ID". This keeps the members with employee IDs 230 and 240 in the drill-down:
    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {values: ["230", "240"]});
  • In the following example, multiple but excluding filter values are set for dimension "EMPLOYEE_ID". This removes the members with employee IDs 230 and 240 from the drill-down:
    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {values: ["230", "240"], exclude: true});

Range Filters

You can filter ranges of members in the drill-down with range filters.

Numeric Dimensions

Note

SAP BW doesn't support numeric dimensions.

The following examples show the use of range filters on numeric dimensions:
  • In the following example, the range filter applied to dimension "EMPLOYEE_ID" keeps the members with employee IDs between 230 and 240 in the drill-down:
    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {from: "230", to: "240"});
  • In the following example, the range filter applied to dimension "EMPLOYEE_ID" keeps the members with employee IDs less than 230 in the drill-down:
    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {less: "230"});
  • In the following example, the range filter applied to dimension "EMPLOYEE_ID" keeps the members with employee IDs less or equal than 230 in the drill-down:
    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {lessOrEqual: "230"});
  • In the following example, the range filter applied to dimension "EMPLOYEE_ID" keeps the members with employee IDs greater or equal than 230 in the drill-down:
    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {greaterOrEqual: "230"});
  • In the following example, the range filter applied to dimension "EMPLOYEE_ID" keeps the members with employee IDs greater than 230 in the drill-down:

    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", {greater: "230"});
  • You can also apply multiple range filters at once.

    In the following example, the range filter applied to dimension "EMPLOYEE_ID" keeps the members with employee IDs less than 230 and greater than 240 in the drill-down:

    Sample Code
    DS_1.setDimensionFilter("EMPLOYEE_ID", [{less: "230"}, {greater: "240"}]);

Time Dimensions

You can set time range filters via API. Multiple ranges are supported.

Here's a scripting example, where time range granularity, start and end are specified:
Sample Code
var current_date = new Date(Date.now());
var current_year = current_date.getFullYear()-8;
var current_month = current_date.getMonth()+1;
var current_quarter = Math.ceil(current_month/3);
var previous_year = current_year -1;

console.log(current_date);
console.log(current_year);
console.log(current_month);
console.log(current_quarter);

//Note : Month is 0 based

//Current Calendar Year
var CurrentYearStart = new Date(current_year,0,1);
var CurrentYearEnd = new Date(current_year,11,31);

//Previous Calendar Year
var PreviousYearStart = new Date(previous_year,0,1);
var PreviousYearEnd = new Date(previous_year,11,31,0,0,0);

var CurrentYearFilter = TimeRange.create(TimeRangeGranularity.Month, CurrentYearStart, CurrentYearEnd);
var PreviousYearFilter =  TimeRange.create(TimeRangeGranularity.Month, PreviousYearStart, PreviousYearEnd);

Table_1.getDataSource().setDimensionFilter("Date_703i1904sd",[CurrentYearFilter,PreviousYearFilter]);
Chart_1.getDataSource().setDimensionFilter("Date_703i1904sd",[CurrentYearFilter,PreviousYearFilter]);
Note
If the time dimensions are set to flat presentation:
  • For tables, the setDimensionFilter() API still works based on the default dimension hierarchy.
  • For charts, the setDimensionFilter() API won't take effect. In other words, to set time range filter on charts via API, make sure that the time dimensions are in hierarchy. For example, you can use setHierarchy() before setDimensionFilter() API:
    Sample Code
    Chart_2.getDataSource().setHierarchy("Date_703i1904sd","YHM");
    Chart_2.getDataSource().setDimensionFilter("Date_703i1904sd",[CurrentYearFilter,PreviousYearFilter]);