Friday, 29 June 2012

SSRS Report: Limit no of columns in SSRS matrix report


you want to add a column break to the matrix control, this requirement can be acheived in Reporting Services, steps are below:
Step one: copy the following code to the custom code area
Dim FlagTable As System.Collections.Hashtable
Dim Flag AS Integer
 Function MyFunc(ByVal NewValue As Object) As Integer
If (FlagTable Is Nothing) Then
FlagTable = New System.Collections.Hashtable
End If
If (NewValue Is Nothing) Then
NewValue = "-"
End If
If (Not FlagTable .Contains(NewValue )) Then
Flag =Flag + 1
FlagTable.Add(NewValue, nothing)
End If
MyFunc = Flag
End Function
Step two: Add a list to your report
1.      Right-click the list ,and then select Properties.
2.      Click Edit details group… button
3.      Type in the expression =Ceiling(Code.MyFunc(Fields!Productname.Value)/2)
Note:
1) Fields!Productname.Value is your column group datafield
2) 2 is the number of the columns you want to display in a row
Step three: Sort the dataset by column group field, and then drag the matrix into the list
1.      Switch to the data tab.
2.      Add ‘order by datafield’ to sort the dataset by the column group datafield  here is a example:
select * from vProductProfitability
where Year=2003 and
MonthNumberOfYear in (1,2,3,4,5,6,7,8,9,10,11,12)
order by Productname
3.      Drag the matrix into the list and preview the report.
Below picture2 is just a sample for you, we can see that original matrix is too long, however picture 2 can fit the width of your report body. Of course you can reset the number of the column in one matrix.
Beside this , you can also spread the columns from one matrix into several matrixes. You can first copy one matrix and then paste it into several ones you want. Then set the filter for each column group to make sure that the total columns’ length in one matrix just fit a page’s width. However I would recommend you adopt the first method, it is more flexible than the second method.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home