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?
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.
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.
The easiest way to achieve this is to first of all write your query which pulls forward the results like this.
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With