Data Engineering

MDX date range selection from SSAS Tabular to SSRS report

Problem:

MDX query with date range, if the date exist, the range selection is returning correct data.

But if specified a date that not exist, the range is not being compared, instead it returns all data (or sometimes no data).

Solution:

Rewrite query with FILTER(), the date range selection works.

SELECT 
[Measures].[Sum of Quantity] ON COLUMNS, 
[PURCHASING].[PO Date].[PO Date].allmembers ON ROWS
FROM(
    SELECT (
//        [PURCHASING].[PO Date].&[2020-01-18T00:00:00] 
//       :[PURCHASING].[PO Date].&[2020-01-21T00:00:00]
        filter ([PURCHASING].[PO Date].[PO Date],
            [PURCHASING].[PO Date].CurrentMember.member_value >= Cdate('2020-01-18') 
        and [PURCHASING].[PO Date].CurrentMember.member_value <= Cdate('2020-01-21'))
               )
ON COLUMNS FROM [Model])

Formulate the string with user input parameters, then can put into SSRS reports:

="FILTER(" + Parameters!DateSelection.Value + mid(Parameters!DateSelection.Value,instr(Parameters!DateSelection.Value,".")) + "," 
+ Parameters!DateSelection.Value + ".CurrentMember.member_value >= Cdate('" + Parameters!StartDate.Value + "') and " 
+ Parameters!DateSelection.Value + ".CurrentMember.member_value <= Cdate('" + Parameters!EndDate.Value + "'))"

Wrap with STRTOSET() in report query:

SELECT 
[Measures].[Sum of Quantity] ON COLUMNS, 
[PURCHASING].[PO Date].[PO Date].allmembers ON ROWS
FROM(
    SELECT (
        STRTOSET(@DataRange)
               )
ON COLUMNS FROM [Model])

Done!