How would you dynamically hide or display a SSRS header based on a parameter? - reporting-services

I need to hide or display the header of a SSRS report based on the value of a parameter. The parameter is called "Show Header?", and the values of this parameter are true and false. Is there a hide property for headers? If so, I'm not able to find it.

I'm not sure if you are talking about the table Headers or the report header (some people seem to use the term interchangeably).
I'm still self learning SSRS so there may be better options out there but a quick test i found the following.
For a Boolean Parameter type:
I used the logic below to hide the visibility based on parameter (you may want to play around with the true/false order depending on your parameter to get it to work how you want):
=IIF(Parameters!ShowHeader.Value, False,True)
Table Headers:
Just highlight the text boxes you want to show/hide and open up the properties, under Visibility select "Show or Hide Based on Expression"
(NB. i found highlighting the full row would only let you select the full tablix properties not the single row so I just shift clicked all the cells and pasted the IIF statement into the "Hidden" Property for the selection in the properties window)
Report Headers:
I am not sure you can hide the Header (couldn't see any immediate hiding properties or options), however you could hide the contents of the header using the same sort of process (right click properties and alter the Visibility setting or add the code into the Hidden property). In testing I found that the header would reduce to remove white space when items where hidden so may work out for you.

The sneaky way I've found to get around the limitation of SSRS on this is to put my "header" in the first row of the first tablix and just hiding the actual report header, which you probably know cannot be deleted. That way, I can show or hide the first row of the tablix by whatever criteria I desire. This method works well for me.

Related

SSRS expression based on visibility of a textbox or column

Is it possible to inspect the visibility (Collapsed/Expanded) of a textbox in SSRS and use this in an expression?
For example :
=iif(Fields!column1 Is Visible,"Use this label","Use this other label")
What I want to accomplish to have the initial value of a column header display some text, when user clicks a particular value the details row are displayed (this is a Tablix), and then the header would change to something else (E.g. initial report state is to hide detail rows and only show Tablix member totals so column displays "... total", when user expands to view details column header changes to "... number".
In MS Access through VBA I could inspect the visible property and create code based on this. Till now haven't found a similar way of doing this in SSRS 2016.
Tried setting expressions for visibility as well as setting expressions for changing value of a textbox.
=IIF(Fields!accountnum.Value IS NOTHING OR Fields!accountnum.Value = TRUE,"Station #", "Station Count")
No error messages. My results should be to change header (textbox) value based on whether detail rows are collapsed (hidden) or expanded (visible).
To answer your first question:
Well of course this is possible, just not they way you want to do it. Here is a smimple example. Lets say your visibilty criteria is the following expression:
'Visibility expression
=IIF(Fields!Category.Value = "Visible", False, True)
Now you dont check on the visibilty with the Is Visible criteria, you just use the same expression again. Like this:
=IIF(
IIF(Fields!Category.Value = "Visible",
Fale,
True) = True,
"This one is not visible",
"This one is visible")
To answer you problem:
They way you want to do it, it is not possible. But you can do this with a workaround.
Add a user defined parameter to your report with two options:
Display details
Hide details
Then add two tablixes to your report. One tablix without the details and one tablix with the details you want to show.
Then go to the first tablix Tablix Properties > Visibility and add the following expression:
=IIF(Parameters!VisibilityParameter.Value = "Display details", True, False)
And the expression for the other tablix visibility:
=IIF(Parameters!VisibilityParameter.Value = "Hide details", True, False)
Now based on the parameter result the talbix with or without the details will be displayed.
You can do this, maybe it won't look too elegant but I'll show you what I did and you can see if it's useful.
Note: Using this method, you can't change the actual column header directly as it's out of scope so this may not meet requirements but you may be able to adapt it. I just thought it was a nice challenge ! :)
First I got some sample data (WideWorldImports sample database) that just gave me a CountryID, CountryName and Continent.
Once you have your data, add a table, drag CountryName into the first column and remove the remaining two columns.
Then right-click the Details row group and do Add Group => Parent Group Choose Continent as the Group By field and check the Add Group Header option.
The table design should look like this, nice and simple.
Next we will set the toggle on the detail rows. Right-Click the "Details" row group and chose "Group Properties". On visibility, click 'Hide' and check the "Display Can be toggled by the report item" to Continent.
We should now have a report that expands and collapses as expected.
Next vertically expand the 'blank cell' just above the countryname as we'll need a bit of room to work with. Make it about 4 times the normal height, we'll change it back later so the size is not important.
In the blank cell, right-click and do Insert => Rectangle.
In this rectangle, right-click and do Insert => TextBox. Double click the text box and type your "collapsed state" column header caption. In my example I just used "Collapsed Header".
Repeat and add another textbox (It must be within the rectangle again). Set this text box to your "expanded state" caption. In this example I just used "Expanded Header".
Next, right click the "Collapsed header" textbox, then properties then set the visibility to Show and the toggle item to Continent.
Repeat for your "Expanded Header" but this time set visibilty to Hide, like this..
Finally, position both text boxes at location 0,0 so they overlap and shrink the cell back down to it's original size.
The final design will look something like this...
When we first run the report we see this.
If we expand a node, we get this.
I do not think this is possible in SSRS. You could change column header text depending on your condition, For Ex: IF (A) then Header A else Header B. But you wish to change Column Header based on some clicks (expand / collapse) on report and this is not possible. I mean we need some data to set condition not clicks.
But maybe someone with more Experience on SSRS would throw some more insight.
This is what InScope() is for. See here for more information

Hide multiple rows or columns in SSRS report with same Expression at same time

I have a report containing a Tablix/table with sets of rows and columns which I am hiding conditionally using Expressions, via the Column/Row Visibility dialog.
If for example I have 3 columns which I want to all have the same Expression to determine their visibility, is there any way for me to achieve this without opening the Column Visibility dialog for each Column and entering the appropriate Expression?
I've tried selecting multiple columns, but then the right-click context menu no longer offers the Column Visibility option (it's greyed out) and I have also tried out the Hidden property of the columns (which can be amended in bulk by selecting multiple columns), but this only stops the columns from being rendered, leaving a blank space where they used to be (rather than how Column Visibility works, where columns to the right of the hidden columns are moved across to fill the gap, like hiding columns in an Excel sheet).
Is it possible to achieve what I'm after, or will I have to continue opening the Column/Row Visibility dialog for each column/row I wish to conditionally hide/show?
If the columns you want to control the visibility for are next to each other, you can create a Column Group for them and manage the visibility via the Group.
Add a new column group at the appropriate level so that only the relevant columns will be included.
If you already have Column Groups this will likely be a Child Group or an Adjacent Group.
If not, you can create an initial Column Group by dragging a Dataset field from the Report Data into the Groups pane.
Insert new columns inside the new group, and move the data from your existing relevant columns into the group.
The new group does not need to repeat, so in it's properties window set Group on: to a plain text value, e.g. "1".
Input the desired visibility settings into the Visibility page of the properties window.
For each of the individual columns inside the group set the Hidden property to False, to remove any other expressions or settings that might interfere.
Not exactly what you are looking for but perhaps a midway point - and this can apply to many things other than visibility (e.g. background colour, tooltip) - edit the RDL directly using View Code. This has the added benefit of being able to implement changes that are almost identical per column instead of identical with a minimum of mouse usage.
Typically I have set one column up the way I like it in the designer and then copy/paste under the other columns. In the case of visibility look for <TablixColumnHierarchy><TablixMemebers>. You will see a list of empty <TablixMember /> items along with the expanded <TablixMember><Visibility><Hidden>=... block where you have set up one column. Simply copy paste that block over the empty items at the position of interest (you will need to count it out unfortunately as there are no identifiers).
Bonus Tip: If you make a mistake or want to change something later, you can do a replace on all expressions at once (optional regex allowed).
Remember to backup or check in your work first because the designer may not open that report again correctly if you make a mistake :-)
Select the columns you want to conditionally hide and press F4 to see the Properties Window. Look for the Visibility node and use the Hidden property to set the conditionally expression.
The expression should evaluate to True for hiding and False for showing.
Let me know if this helps.

SSRS get rid of last page

I have a ssrs report with multiple rectangles.
Each rectangle has "add page break after" property checked. Each rectangle may or may not be visible based on certain conditions.
I want to get rid of the last blank page in the report.
I already set the ConsumeContainerWhitespace to true.
I can't think of another way to get each rectangle on different page and yet having no extra page.
Components that have the PageBreak property also have the Disabled sub-property. The result must be either True or False. When set to True, the page break will not occur. So what you would need to do is concatenate the other components' visibility conditions into one big condition in the Disabled property of the page break. Here's what it looks like in the RDL file (my example will always prevent the page break) :
<PageBreak>
<BreakLocation>End</BreakLocation>
<Disabled>=IIF(1=1, True, False)</Disabled>
</PageBreak>

SSRS 2008 Removing white space when hiding elements

I have been trying to resolve this simple issue for a few hours with no joy.
I have two tables within my SSRS 2008 report which are bound to different datasets and I need to show or hide the appropriate table based on a passed in parameter. This I have done with the hidden property of the table which works as expected. The problem I have is that when hiding the top item and showing the item beneath it I get the white space from the hidden item.
Trivial example
I created two tables and bound them to the same datasource laying them vertically.
I then set the hidden property of the top table to true and previewed the report.
You can see that the first grid is hidden but the white space remains. From my investigations I did see the ConsumeContainerWhitespace property used for this but in my case it did not clear up the white space.
Question
Is there a method of removing the white space for these hidden elements?
I would recommend two solutions depending on whether the datasets are the same.
1: If they share a common dataset then I would nestle them in another table that has 1 column, and 2 rows, and then change the row visibility depending on the parameters.
2: If the datasets are different, I would make each table a sub-report and then change the visibility that way.
Just another workaround caused by SSRS quirks!
This can be fixed by ensuring that the reports ConsumeContainerWhiteSpace property is set to true.
This can be found in the report properties. Click the yellow surround for the report, press F4 to open the Properties pane, and you can find ConsumeContainerWhiteSpace under there.
See also ConsumeContainerWhitespace property to remove blank space in SSRS 2008 report
The behavior can be controlled by following method
1) Right click on the top left box on the tablix and click on 'Tablix Properties' to open the properties for the tablix
2) Click on the "Visibilty" tab on the left hand side of the wizard
3) Click on the "Show or hide based on an expression", click on the Fx and paste the following formula
=IIF(RowNumber("DatasetName")=0,TRUE,FALSE)
4) Make sure to replace the "DatasetName" with the your dataset name (the one that is related to the tablix)
5) Also make sure that the ConsumeContainerWhiteSpace property is set to "True"
ConsumeContainerWhiteSpace property is a report level property and can be changed from properties window for the report. (click on the report outside of the design area)
This worked for me very well.
Select the object, go to properties and set the size to 0,0
Wired. Only contained them in another tablix or subreport then it works in hide them with no white space.

Labels in fields within an SSRS report

I am attempting to reproduce a form within SSRS and fill it with data. The original form has blocks with small labels inside of each box that identifies the entry requested.
I "thought" I could simply use two different tablixes: one for the blocks with borders and labels, and the other one with the actual datafields or expressions, and align the 2nd tablix directly over the first one so that it appears as though the fields are presenting data inside of the labeled boxes.
It looked as I wanted it in design view, but when I went to preview the report, it pushed the 2nd tablix below the first tablix, in effect creating two tablixes, one stacked on top of the other one (not displaying as how I intended).
So, how do I accomplish the form design in the manner that I am seeking?
You should be using a type other than tablix for your report. Use a 'List' instead and you can free float objects as you need them and also nest a tablix as well. A little explanation on list:
You can float images with text boxes and then even change syntax or draw boxes around them and decorate those.
The call out for a field in SSRS is [(value)] with the [] meaning: "Data Column in recognized Dataset"
You can call out Variables with an '#' in front of them [#Test] would be a variable a user would put in called 'Test'.
Whatever size 'List' element is will determine how large it is when it repeats. If you want a strict form ensure the length and width are set correctly on the properties of that element.
If you want it to break every page you can click on the 'List' > Right Click the top left corner > Properties > 'Add a page break before' checkbox.
My example shows a super simple textbox with a dataset that only has three ideas repeat as many times as there are id's, three times. You can apply this to your form as needed.
It looks like you could reproduce that form header quite easily with a single tablix. If you envisage the form as a set of tablix cells like so:
then all you need to do is set the Border properties for each cell to hide the borders as needed (or you could merge the cells e.g those for Applicant and Location).
You can use a tablix with only Header rows, deleting the detail row. If you need multiple forms per report, then put the tablix inside a List region.