Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « How I got started with SQL ServerLearn About SQL Server 2008 R2 Project Gemini And Project Madison By Watching These Videos »
    comments

    When designing a Reporting Services report against a relational database, I would argue that developers most often prefer to utilize a Date/Time parameter type and calendar control for date parameter input. This makes it easy for the user to choose a date with the Reporting Services calendar control instead of requiring the user to type a well-formatted date value or providing the user with a long list of dates in a drop-down list.

    However, when it comes to SSAS, if a developer chooses to add a parameter against a date hierarchy, the end-user is presented with a drop-down list to scroll through and choose dates. This is with good reason. Many times, the user will have the option to choose from different levels of date aggregation. Choosing an entire year or just one single date could be a valid option within the same report. This scenario would be confusing if not difficult to represent in a calendar control.

    That being said, many times reports are more narrowly focused and constrained to a date granularity. In this case, it may be more desirable to allow the user to pick their date with the calendar control. Again, the default behavior when designing the MDX query will present the user with a drop-down containing the members of the date hierarchy. We can change this behavior to present the user with a calendar control instead of a drop-down list.

    I'm working with the Adventure Works 2008 SSAS sample project. In a new SSRS 2008 project, I have added a report to display the Internet Sales Amount by Country, with Date.Date as a parameter. By default, the user interface will look like the image below.

    Image1

    Obviously, this is not a very easy user interface to work with. If we right-click on our data source in the Report Data tab, we can see we have an option to "Show Hidden DataSets." This will give us the definition for the hidden dataset which populates our Date.Date parameter. If we copy the query text and paste it into SQL Server Management Studio, we can see that in this case, our parameter's value takes on the format of [Date].[Date].&[yyyyMMdd]. The format may be different depending on the individual Date hierarchy setup. So, what we need to do is use a calendar control yet still supply a proper string to our main dataset as a parameter value. We can accomplish this with a VB function within the report.

    Add a new parameter to the report named Date. This parameter should have a Data type of Date/Time to ensure that it is rendered to the user as a calendar control. In the properties pane of our Report, we can add the following VB function in the Code window:

    Function GetDateMemberString(DateValue As DateTime) As String
    Dim RetVal As String = ""
    RetVal = "[Date].[Calendar].[Date].&["
    RetVal &= Format(DateValue, "yyyyMMdd").ToString & "]"
    Return RetVal
    End Function

    This code will accept a DateTime value as input, and return a string as output. The output value will have a format which matches our Date hierarchy format.

    Next, if we right-click on our main DataSet and view the Parameters tab, we will see that our date parameter is mapped to our original, wizard-generated @DateDate MDX parameter. We can change the Parameter Value expression to the following: =Code.GetDateMemberString(Parameters!Date.Value).

    We can now hide or delete our original, wizard-generated date parameter and re-rerun the report. We should now end up with a user interface as shown below

    Image2

    This is definitely much easier to work with than the original version. One other thing to note is that depending on the scope of data in the cube, the query for our main DataSet may need to be altered to remove the CONSTRAINED argument from the StrToSet functions within the query. If a user passes in a date which does not exist in the Date dimension, then SSRS will return an error if we call the StrToSet function with the CONSTRAINED argument.

    Please also see related article on this topic Building OLAP Date Dimensions

    5725 views
    Instapaper

    4 comments

    Comment from: Ted Krueger (onpnt) [Member]
    *****
    Ted Krueger (onpnt) Excellent blog riverguy!
    09/02/09 @ 18:26
    Comment from: SQLDenis [Member] Email
    SQLDenis you know one of these days I will give SSRS a shot....I heard it is much improved with the 2008 version
    09/03/09 @ 07:58
    Comment from: Ted Krueger (onpnt) [Member]
    Ted Krueger (onpnt) Yes, 2008 has some good improvements but 2005 was pretty good at the same time. I still think the best rapid report development platform out there. most of all for developers taking it on with little training.

    Now 2000 SSRS is a different story ;)
    09/03/09 @ 15:32
    Comment from: Naomi Nosonovsky [Member]
    Naomi Nosonovsky Do we need to download http://msftasprodsamples.codeplex.com/Wiki/View.aspx?title=SS2008!Readme_AMOAdventureWorks to make it work?

    I wanted to try this out, but the instructions are not precise for me as what I have to set up first.

    I have AdventureWorks 6 different databases installed.

    Could you please expand your blog a bit for a newbie like me?

    Thanks again.
    09/05/09 @ 23:03

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)