SSRS. List distinct values from a SharePoint list

If you create reports using Report Builder or BIDS it's avaiblable to use SharePoint list or document library as a DataSource. To retrieve data in this case CAML query is used, thus there is no direct way to get only distinct values from DataSet.

And such is the need at least to fill parameter values:


So we have a report using SharePoint list as a DataSource, DataSet, selecting values from one column of the list and Parameter wich displays (has to display) distinct values from the DataSet.

And if you run the report as it is, you will see duplicate values in the parameter drop-down list (see picture above). That is exactly what the DataSet returns:


To process data before transfering it to the parameter we need to pass through its a function (VB.NET is already some closer), wich sorts and removes duplicate values from the array transfered to it.

For such cases the report allows us to use custom code. It can be either reference to assembly or just plain text. In the case of the plain text you have to use VB.NET because of support of C# is not implemented.

Installation of Report Builder requires .Net Framework 3.5, which allows us safely use Linq. First of all add reference to System.Core assembly:

Now in Code tab point out our static function, that accepts a report parameter and returns unique values for it:

  1. Public Shared Function GetUniqueValues(parameter As Parameter) As String()
  2.     Dim items As Object() = parameter.Label
  3.     System.Array.Sort(items)
  4.     Dim res As [String]() = System.Linq.Enumerable.ToArray(System.Linq.Enumerable.Cast(Of String)(System.Linq.Enumerable.Distinct(items)))
  5.     Return res
  6. End Function

You can use Label property of parameter instead of Value property. It may look something like this:

Reference to values from the data set by using Expression in the parameters is impossible. As a result, we have two parameters: a hidden parameter that retrieves data from the data set and the second one that filters the data and displays it to the user:

Performance on large lists in this case would be a bottleneck, but I couldn't find out the other way. I can only add that the long waiting time of generation can be replaced with a subscription. It allows to obtain report, such as e-mail in PDF format everyday at 8:30 AM.

Users will not have to "chase" for information. The information itself will come to them at his convenience. In addition, corporate email is almost always available, which is not the corporate portal.

Demo report is here.