Wednesday, October 24, 2012

Conditionally hide SSRS expand/collapse button

Over the last year and a half, I've transitioned into a full-time BI role at my new job. Among the many changes I've had to deal with, learning the differences between Crystal Reports and SSRS (Microsoft SQL Reporting Services) has been one of the most interesting.

Each tool has its' own nuances and issues. I've found that each has significant pros and interesting cons. Take for instance SSRS:
Significant pro:

  • Horizontal grouping. Let's not talk about cross-tabs in CR, as I don't consider that horizontal grouping - too many weird formatting and display issues. It's a hack, at best. It's ugly, users don't like it, and I hate developing them. 
Significant con:

  • Multi-item editing. You mean to tell me you don't support me clicking on a number of items, right clicking and having all the similar formatting tools at my disposal? Wow. Sure, I can click them all, then go into properties and format, but I'd have to remember the SSRS code for a percent or a standard currency format. It's just strange.

So, with knowing that each tool has great features, and great quirks, here's one of the quirks I found in SSRS, and how I worked around it.

Situation: Users request a high-level report detailing how much each support call costs, at each support level (tier 1, tier 2, and tier 3). Summary totals are presented at the top, and detail assumptions and data that drive the total is presented at the bottom. 

Gotcha/caveat: Detail data (which includes avg headcount cost/salary per level) should be hidden by default, toggled on request. Detail data also should only be shown to specific users. Basically, only managers can see the report, but only a subset of said managers can see the detail data.

There is no way to conditionally show a toggle item in SSRS that I know of (this is using SSRS 2008 R2). 

Workaround: It's very simple, almost silly really. I placed the matrix table containing the detail data inside a rectangle. The rectangle's visibility options are set to hide on load, and are set to be toggled by another text box in the summary data.

Great, that gets me to the point where the user can toggle, but how can I control who toggles the switch? You can't. But, you can control who sees the textbox the toggle is in. Simple answer, make the visibility settings on the toggle textbox change based on the user.

SSRS has a built in user parameter that tells you who is attempting the access the report, so we can use that parameter to know who is coming in. 

Here you have two options:
1. Hard code the users in the expression of the toggle text box (tb76 in my case. Original, I know. Terrible naming conventions). 
2. Pull from a table.

I chose route 2. I built a Dom_ReportUsers table in my database that stores the name, credentials, reportname, and type (is it an entire report, a subsection of a report, etc) for any report with special permissions. I've found it very useful.*

So, I have a 2nd dataset in the report called "Users" that pulls everything from that table, filtered with the hardcoded report name and where the credentials match the aforementioned Users parameter.

Then, on tb76, I set the visibility property to "Show or hide based on an expression" and set the expression to =IsNothing(First(Fields!Name.Value, "users"))

This way, if the user isn't in that Dom table for this report section, they don't see that box, and can't toggle.

It's pretty simple, and works well.



* The table is probably only needed if you want to control permissions for multiple reports or sections from a single place. I didn't want to have to spin up visual studio and redeploy to give someone new access to that section, plus I'm using this table to control security on 3 reports currently. Additionally, with this report, we're doing 2 levels of filtering, one where only managers can see the report, and then section filtering where only certain managers can see the details, if that makes sense.

No comments: