Search This Blog

Wednesday, 17 September 2014

Customized Sorting Using Parameter

Let’s give some customize option to our end user to sort the report output as per their choice.
Let’s go through with the following steps:

Step1. Create a new parameter and list out all the field names under Available Values property of the parameter. Specify field names under Label as you want to show to your end user and keep the value same as in your database field by comma separator and sorting order. Refer Image-1
 
Image-1













Step2. Now we need to write our query in a dynamic fashion in dataset. So open your dataset properties and under query window, specify your query.
Refer Image-2
 
Image-2





















Step3. Now put following expression at the end of your dataset query. Refer Image-3

=<Your Dataset query>+IIF(Parameters!p_sortby.Value="None"," ","Order by "+Parameters!p_sortby.Value)

 
Image-3

Sorting using Multi-value parameter

Let’s give an option to our end user to sort the report output as per their selected fields. Not by report design.
To keep the sorting feature more rich and relevant, let’s go through with the following steps:

Step1. Create a new parameter (enable Allow Multiple Values) and list out all the field names under Available Values property of the parameter. Specify field names under Label as you want to show to your end user and keep the value same as in your dataset field name. Keep the order of the fields in which you want to sort the report output. Refer Image-1
 
Image-1














Step2. Now open property window of your table’s group and select Sorting. Refer Image-2
 
Image-2











Step3. Now put following expression under Sort by and also set required Order for each of fields that are available in your parameter list. Refer Image-3

=IIF(join(Parameters!p_sortby.Value,",").Contains("EmployeeName"),Fields!EmployeeName.Value,Nothing)

 
Image-3


Tuesday, 16 September 2014

SSRS Forward Dependencies is invalid

It has been seen many times developer’s who are new to SSRS experience this issue (Forward dependencies is invalid).
Let’s reproduce the issue
In this example I have used the AdventureWorksDW database .
DataSource =AdvDw
DateSet=fwdDep
Lets create a report ForwardDepandencies.rdl in your BIDS, In which your user want to see the following information about employee  in Sale territoryRegion wise based on SaleterritoryRegionWise
First Name , Last Name ,Phone number, SalesTerritoryRegion
To create this report you  need write some SQL query which will display the information about employee
SELECT 
EMP.FirstName,
                EMP.LastName,
                EMP.Phone ,
                ST.SalesTerritoryRegion,
                ST.SalesTerritoryKey
FROM dbo.DimEmployee Emp WITH (NOLOCK)
INNER JOIN dbo.DimSalesTerritory ST with (NoLOCK)
on EMP.SalesTerritoryKey=ST.SalesTerritoryKey
WHERE ST.SalesTerritoryKey=@saleTerritoryKey

2. Create a Data source as you wish
3. Create a Dataset as you wish
4. Right click on your dataset put you SQL in Query and click Ok
5. When you will expand parameter folder in BIDS green circled 2 in the below Image 

In the above example we need to display the information a few columns
First Name,Last Name,Phone number,SalesTerritoryRegion 
but our Sql consist one more column SalesTerritoryKey to which we are passing as parameter value to display the employee information in SalesTerritoryRegion  wise . When user will pass the saleterritoryKey in employee information for that SalesTerritoryRegion  should display in your report
Usually developer who is new to SSRS tries to map the Parameter  value  from resultset  dataset value
As in this example resultSet dataset  (FwdDep) SaleterritoryKey value
When you will Right Click on parameter as in this example Saleterritory

It will ask you to fulfill the following fields
Name : name of the parameter
Prompt: parameter text which you wish to display in report
Now you click on Available values see below image
Select get values from query , See carefully on below image red circled field. Here we are passing  the value to parameter from resultset Dataset to result Dataset which is creating Forward Dependencies.


Hence we are getting below error 


To resolve this issue we need the following step
1.     Go to thie BIDS , Right Click on datasource  Add another dataset as you wish in this example we have created FwdPP
2.     Write the below sql in query window see below image
SELECT DISTINCT ST.SalesTerritoryRegion,ST.SalesTerritoryKey from dbo.DimSalesTerritory ST with (NoLOCK)

Click OK , now you will see another Dataset in your BIDS
























Now go to you parameter folder right click on your  Saleterritory parameter .
Click on available values 

Pass the parameter like
Dataset: FwdPP . the vales from this dataset will be passed to resultdataset  FwdDep.
Value field : Which will be passd to resultset parameter i.e (WHERE ST.SalesTerritoryKey=@saleTerritoryKey) in resultset datset sql. SaleTerritoryKey from FwdPP  will be passed to FwdDep.
Label Field which you need to display in your report
Now you preview your report select the value you will get report as your selected parameter.


Sunday, 14 September 2014

Sorting on column click



We see many Web applications where web page has been designed to give a rich sorting feature to end user. There uses click on any column and entire data gets sorted according to that column. Let’s design a report we can give this rich sorting feature to our end user.
Here I am assuming that you are done with your report design and you have to just introduce sort feature on various columns in your report.

Step 1. Right click on that particular column and 
select Text box Properties option. Refer Image-1
Image-1











 
Step 2. Now select Interactive Sorting option and also check the Enable sorting option on this textbox. Refer Image-2
 
Image-2
  
Step 3. You see other options available there and those are as
·        Choose what to sort:
(I) Detail Rows: if your report has only one group/row i.e. detail group/row then choose this option
(II) Groups: if your report has multiple groups and you want to sort the result specific to a group then choose this option
·        Sort by: select the available field name on which you want to perform an sort operation
·        Apply this sorting to all groups and data regions in: choose this option, if you want to sort the whole records specific to your dataset/table/table group

Step 4. You need to repeat the above steps on each column one by one on which you want to give sort feature. Once you done with this and preview your report, the columns will have icons as up-down arrows. Refer Image-3

Image-3



On Demand Sorting



Let’s give an option to our end user to sort the report output as per their choice. Not by report design.
To keep the sorting feature more rich and relevant, let’s go through with the following steps:
Step 1. Create a new parameter and list out all the field names under Available Values property of the parameter. Specify field names under Label as you want to show to your end user and keep the value same as in your dataset field name. Refer Image-1
Image-1















Step 2. Now open property window of your table’s group and select Sorting. Refer Image-2


Image-2






Step 3. Now put following expression under Sort by. Refer Image-3
=Fields(Parameters!p_sortby.Value).Value
Image-3