Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get 2nd Value in Dataset in Reporting Services

Tags:

ssrs-2008

This seems to be a very simple question, but I am trying to get the 2nd value in a dataset to display as a matrix's header value.

In this report, lets say that I have 2 datasets. In Dataset1, I have a query that pulls down 3 values for a parameter dropdown selection. In Dataset2, I return a result set and have bound it to my matrix.

Within the matrix, I have my repeating columns, and then 3 additional grouped columns to the right that have aggrigate values that I want to display. On the header of those 3 columns, I want to display the 3 values displayed in my Parameters dataset. Within the context of the matrix (and its dataset), I can get the first and last values of a different dataset (Dataset1 in this case) by using:

=First(Fields!DateDisplay.Value, "Dataset1")
=Last(Fields!DateDisplay.Value, "Dataset1")

I need to get something like:

=Second(Fields!DateDisplay.Value, "Dataset1")

How do I pull this off without violating the scoping rules on aggregate columns?

like image 935
Nathan Avatar asked Jan 04 '11 13:01

Nathan


People also ask

How do I pass multiple values to a parameter in SSRS?

In the Report Data pane, expand the Parameters node, right-click the report parameter that was automatically created for the dataset parameter, and then click Parameter Properties. In the General tab, select Allow multiple values to allow a user to select more than one value for the parameter.

How do I display parameter values in SSRS report?

To provide available values for a parameter from a dataset In the Report Data pane, right-click the parameter @StoreID, then click Parameter Properties. Click Available Values, and then click Get values from a query.


2 Answers

For SSRS 2008 R2, you can do this if each row of your dataset has an identifier column by using the LookUp() function.

=LookUp(1,Fields!Row.Value,Fields!DateDisplay.Value,”Dataset1”)
=LookUp(2,Fields!Row.Value,Fields!DateDisplay.Value,”Dataset1”)
=LookUp(3,Fields!Row.Value,Fields!DateDisplay.Value,”Dataset1”)

If you do not have an identifier column you can use ROW_NUMBER() to build one in.

Query:

SELECT ROW_NUMBER() OVER(ORDER BY DateDisplay) AS Row, DateDisplay
FROM Dates

Results:

Row DateDisplay
--- ---------
1   June 1st    
2   March 12th      
3   November 15th

Here is a link to a similar thread in MSDN Forums: Nth row element in a dataset SSRS

like image 57
dotNetE Avatar answered Oct 31 '22 09:10

dotNetE


If you are using SSRS-2012 or 2014 then one has to use below expression.

=LookUp(AnyRowNumber, Fields!RowNumber.Value,Fields!DisplayField.Value,”DatasetName”)

I have tried above it was not working in my case.

like image 35
pedram Avatar answered Oct 31 '22 09:10

pedram