This post will be particularly interesting to if you have a custom built application which utilizes SSRS API/Libraries to create reports within your applications.
All of us who have worked with SQL Server Analysis Services (SSAS) are aware how easy it is to incorporate parameters from any Dimension into SQL Server Reporting Services (SSRS) reports. With a particular date hierarchy in place, it provides a lot of relief to end user on how they want to slice their data, and there is no need to create multiple datasets just to populate these parameters. SSRS does it itself in the form of hidden dataset, executes that query first, and populates the field as per your selection.
What was particularly difficult today was to use a standard date picker parameter on SSRS and map it back to date hierarchy on the SSAS cube, as these dates are stored in a text/string format inside the cube. If you have done this numerous times, you are already aware that there is no easy way to do this, and if you have not, please bear with me here.
In order to get the parameters to work, let us focus on a MDX snippet (query) first:
FROM ( SELECT ( STRTOMEMBER(@FromDateDateString, CONSTRAINED) : STRTOMEMBER(@ToDateDateString, CONSTRAINED) ) ON COLUMNS FROM [InternalReports]) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
The @FromDateDateString part of the query maps the input parameter in the dataset, and STRTOMEMBER(.., CONSTRAINED) makes sure that your input parameter can be mapped to a value inside the cube. No magic there!
Problem is: SSRS passes the date string in date time format, and it does not map properly to the date dimensions resulting in a few errors. In order to get rid of the problem, first, you have to understand how your date dimension (particularly formatting of date field) looks like. In my case, it looked like the following:
In order to map this properly to the cube, I created two additional parameters as placeholder parameters for the From: and To: parameters and set the visibility to visible (for debugging/dev). In the available values, I set them to none, and in the default values, I set them to the following expression:
=”[Date].[Date Hierarchy].&[" & Format(Parameters!FromDateDateString.Value, "MM/dd/yyyy") & "]“
The trick is to construct a string in the same format as SSAS would take them in using expressions. In my case, I had to set it to “MM/dd/yyyy” format, as it appears in my date dimension. After the dates are selected from the date picker, you can see how this gets resolved, before you decide to set these parameters to hidden.
After this resolves successfully, you can set your dateset parameters to map to these newly created parameters. After all is done successfully, you can hide the newly created parameters and only display datepicker parameters.
Inside the SSRS Server, this looks like the following:
Please let me know if you have any questions.