Download presentation
Presentation is loading. Please wait.
Published byStewart Long Modified over 8 years ago
1
Sponsored by: Professional Association for SQL Server Advanced Reporting Services Slicers
2
Slicers are popular
3
In Excel add a slicer to a pivot Slicer
4
… click on slice to change Slicer
5
… and you can multi-select
6
So slicers A list of slices of your data you can select Selecting slice adds or removes that slice of data Selecting another slices adds that slice of data
7
What does it require in RS A list of slices Ability to select a slice A chart to display the data Filter the chart by the slice(s) selected Allow multi selections Easy ….
8
So how do we do that in RS
9
A button Clickable RS Action Show its selected Expression based background Stay clicked Parameters store state
10
Set of buttons (slicer) A button for each slice a Data List or Table Each button to be selected Multi valued parameters And some VB Code
11
A chart Now that’s easy I can do that. I hope
12
Connect the chart to the slicer Either filter the chart or Filter the query with parameters
13
Filtering or Parameters Filters SQL with Parameters Less for SSRS to process Complex for SPs Ugly with lots of values CachingReuse of data Use formatting to hide
14
So that’s for selecting one value What about selecting more than one value
15
Allowing multiple values Allow parameter to have multi values Filter needs to work with multi values And then the fun bit : - Change the formatting of the buttons Change the actions of the buttons
16
Multi valued parameters and SQL For AdhocSQL –Use IN clause and RS does magic For SPs –Use a delimited list and a split function –Can generate a delimited list using JOIN function
17
Formatting the button Need to look at ALL the selected slices Need to use some code Custom code is written in VB.Net –No intellisense –No colour coding –No debugging Easy to write and debug in VS and then transfer back to RS
18
Custom Code in SSRS Access through report properties Put code in here
19
Finding if a value is in a parameter list Multi valued parameters are arrays VB.Net has function to find a value in an Array Function IsInList(ByVal value As Object, ByVal list() As Object) As Boolean Return Array.IndexOf(list, value) >= 0 End Function Array.IndexOf() Wrap function in a custom function for ease
20
Changing the background expression =iif(Code.IsInList(Fields!Region.Value,Parameters!Regions.Value)," ButtonSelected","ButtonUnSelected") Our background expression then becomes “Code.” Is used to reference our custom function The name of our custom function The value we want to look for in the multi value parameter The multi value parameter. “.Value” returns the array of values currently selected
21
Caution - using custom code Don’t fool with internals You will end up in a mess RS is not strict –Code will silently fail –Behaves differently when deployed
22
Toggling slice from parameter Find out if the slice is selected –Use the parameter values Generate a new array –Because you don’t want to mess with internals Either add or remove the slice
23
Removing an item from list Create a new array of the right size Dim NewList(list.Length - 2) As Object Copy all the items except the one to remove 'Move the items along to overwrite the item we don't want If pos > 0 Then Array.Copy(list, 0, NewList, 0, pos) If pos < list.Length - 1 Then Array.Copy(list, pos + 1, NewList, pos, list.Length - pos - 1) Dim pos = Array.IndexOf(list, value) 'Find the item Find out if the slice is selected
24
Adding an item to the list Create a new array of the right size Dim NewList(list.Length) As Object Copy all items and add the slice at the end list.CopyTo(NewList, 0) NewList(NewList.Length - 1) = value Dim pos = Array.IndexOf(list, value) 'Find the item Find out if the slice is selected
25
Complete toggle code Function ToggleFromList(ByVal value As Object, ByVal list() As Object) As Object() Dim pos = Array.IndexOf(list, value) 'Find the item If pos >= 0 Then 'Need a new list to avoid screwing around with 'the parameters array passed in. Dim NewList(list.Length - 2) As Object 'Move the items along to overwrite the item we don't want If pos > 0 Then Array.Copy(list, 0, NewList, 0, pos) End If If pos < list.Length-1 Then Array.Copy(list, pos+1, NewList, pos, list.Length - pos - 1) End If Return NewList Else Dim NewList(list.Length) As Object list.CopyTo(NewList, 0) NewList(NewList.Length - 1) = value Return NewList End If End Function
26
And here’s one I made earlier
27
That’s all a bit unpleasant
28
How to make it nice Put the code in an assembly Deploy the assembly Reference the assembly in a template Wrap the slicer into a report part Now you have drag and drop slicers
29
How can you take it further Add interactions to other elements –Charts, lists, axes Add additional slicers Add group selections Connect slicers together –Careful of circular dependencies
30
What we’ve covered Custom formatting of an item Using actions to add interactions to a report Using parameters for functionality Using multi value parameters to filter Use code to manipulate parameters
31
Lessons Learnt RS is incredibly flexible and versatile Code behind opens up lots of possibilities Multi-valued parameters are tricky Adding interactivity is very possible Your users will love it
32
So get slicing
33
PASS Pre conference – More of the same If you liked this session you’ll love my precon. It’s a whole day of content like this. How to make reporting services work for you. For more details go here http://tinyurl.com/AdvancedRS-FAQ and for more details on the summit go to http://www.sqlpass.org/summit/2011/
34
I am Simon Sabin Independent SQL Server Consultant and Trainer Founder of SQLBits Microsoft Certified Master SQL Server SQL Server MVP Email: Simon@SQLKnowHow.comSimon@SQLKnowHow.com Blog: http://Sqlblogcasts.com/blogs/simonshttp://Sqlblogcasts.com/blogs/simons Twitter: @simon_sabin
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.