Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show data on SSRS report grouped week or month based on parameter

I'm trying to achieve the appropriate grouping to be shown on SSRS report which is driven by the 'weekly' or 'monthly' parameter defined in SSRS (not a argument for sproc). For that I'm using following in the Category Groups expression for the field called "Date" (format is '2014-03-01' as example):

=IIF(
  Parameters!date_range.value="Weekly", 
  DATEPART("week", Fields!Date.Value),  
  DATEPART("month", Fields!Date.Value)
)

This results in the following exception:

The Value expression for the field ‘Date’ contains an error: Argument 'DateValue' cannot be converted to type 'Date'. (rsRuntimeErrorInExpression). An error has occurred during report processing. (rsProcessingAborted)

Why?

like image 604
user2896521 Avatar asked Aug 22 '14 19:08

user2896521


People also ask

How do you set cascading parameters in SSRS?

To create cascading parameters, you define the dataset query first and include a query parameter for each cascading parameter that you need. You must also create a separate dataset for each cascading parameter to provide available values.

How do I use IIF in SSRS expression?

Using IIF Function in SSRS We are going to add a new field to the report data set to determine if the Order Year is the Max or Current Year. As shown below, the dataset properties window is opened, and the Fields tab is selected. After clicking Add, at the bottom of the list a new field is added.


1 Answers

The easiest way to achieve this is to first of all write your query which pulls forward the results like this.

SQL Server Query

SELECT  DATEPART(MONTH, Date_Column) AS [Monthly]
       ,DATEPART(WEEK,  Date_Column) AS [Weekly]
       ,SUM(Some_Column)             AS Total
FROM Table_Name
GROUP BY DATEPART(MONTH, Date_Column) 
        ,DATEPART(WEEK,  Date_Column)

SSRS Report

Add a Matrix Data region. Drag and drop Total column to DATA.

Create a Parameter say GROUP ON of Text type, and provide values

1) Weekly
2) Monthly

Now below in ROW GROUPS pane, right click the only visible Row Group and goto GROUP PROPERTIES In GROUP ON section put following expression.

=IIF(Parameters!Groupby.Value = "Monthly", Fields!Monthly.Value, Fields!Weekly.Value)

Use the exactly same Expression on Data region ROWS section.

For Column name you can use the following Expression...

=IIF(Parameters!Groupby.Value = "Monthly", "Monthly", "Weekly")

and you are good to go.

Important Note

SSRS is a cool tool for data presentation, not so cool when it comes to Data manipulation, to get better performance do all sorts of Data Manipulation closer to source (database, SQL Server).

All of the presentation stuff should be handled on SSRS.

like image 125
M.Ali Avatar answered Sep 28 '22 19:09

M.Ali