Thursday, July 18, 2013

Create Calendar style reports in SQL Reporting Services

Sometimes it is easier to visualize the activity related information in a calendar view. Here are a few scenarios where Calendar style report provides a better view of information than a standard table or list.


- number of outbound telephone calls by salesperson or department in a telemarketing company
- billable and non-billable hours by consultant/department in a consulting company
- Internet sales on the e-Commerce web site


You can create a calendar style report in SQL Reporting Services using a matrix type data region. The matrix will have weeks of the month as rows and days of the week as columns.

In this article, I will explain the steps required to create such a report from AdventureWorksDW database (available for download on Codeplex). I have also provided a link to download the report definition (RDL) file below.


Here are the key points to note for creating a calendar style report using SSRS.


1. Dates or Calendar table: We will use this table to include date, week number and day of the week information in the data set. This table contains all dates in each calendar year you will be reporting for. The AdventureWorksDW has the DimDate table that contains this information. If you do not have such as table in your database, you can create a temp table and use it in the query.


2. Outer Join: We will need to use the Outer Join between the dates table and the fact table so that all dates are included in the data set whether there is data or activity for that date or not.


3. Week Number: We will need this field to generate the matrix. This field has erroneous data in the AdventureWorksDW database. Therefore, I had to create a calculated field to calculate this value. Please see below for details.


4. Use Matrix to create the Calendar view. The Matrix has the WeekNumber as the Row Group and DayNumberOfWeek as the Column Group. These fields are used only for grouping and should be hidden in the final report design. The WeekNumber can be any number from 1 through 53. The DayNumberOfWeek can be any number from 1 through 7 – 1 being Sunday and 7 Saturday.


5. The matrix can have from 4 to 6 rows depending on the number of weeks in the month and the day on which the month starts. It always has 7 columns – one for each day of the week.


The screen shot below shows the query used for the data set used in the matrix. Note the LEFT OUTER JOIN between DimDate and FactInternetSales tables.




As mentioned earlier, the week number field in the DimDate table in AdventureWorksDW has erroneous data. Therefore, I created a calculated field WeekNumber as follows:


=DatePart(DateInterval.WeekOfYear, CDate(Fields!FullDateAlternateKey.Value))


The following screen shot shows the report in the design mode. As you will notice, the matrix uses WeekNumber as the Row Group and DayNumberOfWeek as the Column Group. EnglishDayNameOfWeek is used to display the days – Sunday through Saturday.




The following screen shot shows the sample output for the month of June 2007. This month has 5 rows representing 5 weeks and 7 columns representing Sunday through Saturday.




The following screen shot shows the sample output for the month of September 2007. Note that this month has 6 rows representing 6 weeks.




The report definition (RDL) file is available for download here.


Please also see the related post to display gauge indicator on the calendar style report.

23 comments:

PP wicho said...

Great and simple!!!

Thank you very much

PP wicho said...

Great and simple!

Thank you very much

Anonymous said...

that download link is not working

Abi Shende said...

The download link should be working. Try this: https://onedrive.live.com/?cid=9678C45F4A823615&id=9678C45F4A823615%21122

Anonymous said...

hi, the solution is simply superb. i really appreciate it. i have an additional requirement, in the calendar report instead of sum(totalsales) i need to print a list of employees. So for that i placed a table and binded the employees to that table. now, my question is how can i limit the rows inside that table ?.what i mean is i need to show only 10 employees per page. how can i do it ?

Abi Shende said...

Hi Anonymous,
I am not clear about your requirement. Can you explain what you mean by 10 employees per page? Do you mean 10 employees per date? If so, depending on your needs, you may be able to use the top 10 query.

Anonymous said...

Hi,

Thanks for posting this. It looks like it would be very helpful for me, but the download link isn't working.

Is there any other link I can access it from?

Thanks

Sher said...

Thank you for this example. It works great. I wrapped it in an outer list so that I could run the report for multiple years, months and employees and get the calendar just for their activity.

However, one issue I have is that if it is a Day of the week where in that month there is no record, it is showing previous or later weeks data.

i.e. so I ran it for January 2012 ... the 31st is on a Tuesday so it shows it in week 5 under Tuesday but then the next box shows Day 4 ... Well the 4th of January is a Wednesday.

Then for February, the first 3 days (Sunday - Tuesday) show 5, 6, 7 then 1, through to 27. It is missing 28 and after 27 it shows 7 again and then 1, 2, 3, 4.

I know I had this working but because I had to mess around with getting multiple calendars to print I'm not sure how I messed this up? Any help?

Anon said...

Hi,

This is really helpful, thank you. I am however struggling with how to split the value box in the matrix as you have done to show the daynumber in the upper left corner of the value box with the sum in the bottom right.

Any help would be great,

Thanks

Abi Shende said...

I suggest that you download the RDL file and review the design. You will find the link at the bottom of the post.

Unknown said...

Hello sir i want to ask that if i want to run this calendar report on multiple months so what can i do.

Thank you

Abi Shende said...

@Adi Khan
You should be able to modify the report to group the records by month and print each month on a new page. Alternatively, you can create a report and embed a month report as a sub-report which may be easier.

Unknown said...


Hello good afternoon. I made a copy following your report, but I did not find where you put the expression
DatePart (DateInterval.WeekOfYear, CDate (Fields! FullDateAlternateKey.Value)),
the naming of the days of the week in my case is repeating.
please help me

Abi Shende said...

@Magna Joaquim
This is a calculated field. You can create it within the dataset. Hope this answers your question.

Unknown said...

Hi, great report but how can I make the week start from Monday instead of Sunday?
Thanks for any suggestions.
Thanks.

Abi Shende said...

@Unknown
By default, DayNumberOfWeek can be any number from 1 through 7 – 1 being Sunday and 7 Saturday. You can use the Case statement in your SQL query to add 7 if DayNumberOfWeek = 1. Then your numbers will be 2 through 8 where 2 = Monday and 8 = Sunday.

remone said...

i want to create a year planner thats used to plot meetings for the entire year any idea how to do this?

Abi Shende said...

@remone Please download the RDL file and explore it. The report displays one (selected) month. However, you should be able to modify the report to group the year's data by month and display each month separately.

Unknown said...

Hi, appologies, I know this is an old post, but I have managed to follow the instructions, which seems to have worked, however, I am having an issue where I am getting data before and after the first and last day of the month. so say the first of the month is on the Wednesday, the Monday and Tuesday before this day should be blank but it is populating with data from the next Monday and Tuesday. The same is occuring at the end of the month. What am I doing wrong? Please help.

Abi Shende said...

@Unknown Please check your query. It should select data for the month you want to report on. Please see the screenshot in the post that shows the SQL query. You may also download the sample and review it.

Unknown said...

First of all this is great!!!! I'm having the same issue as Unknown. June 1st is a Tuesday but I"m getting data on Monday (assuming May 31st). This data is also what's showing on Monday the 7th. Was there ever any resolution to this?

Abi Shende said...

Hi, glad that you found it useful. Please see my earlier response re: this issue. Thanks.

Ad said...

Thank you!!!