Hide Empty Subreport in SSRS2008 R2 - ssrs-2008

I have added a subreport to my report. The aim is simply to hide the subreport if there is no data in it.
NoRows property was mentioned on this thread on Microsoft forums, but I guess it is for SSRS 2005 as the thread as quite old.
Isn't there any obvious way to hide subreport if there is no data in it? I could hide the tablix in the subreport itself, but I also need to hide the row where subreport placed. To do this I need an indication whether the subreport has data or not in the main report.
Could you give a clue to sort this out?

I had a similar problem a year ago or so. My vague recollection of this:
The default behavior as I recall was that SSRS won't show the subreport if the datasets in the subreport return no rows. This accomplishes half of what you want, but doesn't let the parent report know whether to hide the subreport area or not. IIRC, the NoRows property only controls what will be shown in this case, but it's not easily checked at run-time to change other properties.
My final solution was to create a stripped down query in the parent report that would indicate whether or not the sub report would have any rows. I used this to control row and subreport visibility.
I suspect there's a more elegant answer...

I placed the subreport in a row of its own. Then I edited the rdl file in a text editor and set the row height to 0 (The designer will not let you do this).
With the row height at 0, the row is practically hidden, until the subreport gets data, at which point, the subreport determines the row height, and it all looks normal again.
An alternative to editing the rdl may be to set the height of the row in code, I haven't looked into that though.

I ran into this issue and none of the answers worked for me. In my case I was converting a Crystal Report to an SSRS report and was using a sub-report that could occur for every group. This was fairly simple in Crystal Reports because you could suppress empty sections with a checkbox.
What worked for me in SSRS and was very clean was to add a subquery/CTE to my main report query that got a count of the number of rows that would be present in the sub-report data. For example:
SELECT CommonCriteria, Count(*) [RowCount]
FROM TableUsedInSubReport
GROUP BY CommonCriteria
Then just join this subquery/CTE to your main query on the common criteria. Once you have this it is very simple as you just right click on the far left of the row in the tablix and select Row Visbility. Then you use an expression such as...
=IIF(Sum(Fields!RowCount.Value) > 0, false, true)
That way if there are any rows to display in the sub report it will display them and if there are no rows in the sub report it will hide it and not leave white space.

i ended up using rectangle underneath the subreport - that way if subreport returns nothing, rectangle underneath it will control appearance of the cell - in my case I needed to grey out the cell if subreport returns nothing.
This thread gave me an idea How to supress empty subreports in SSRS 2008 but I did not even have to use expressions because by default SSRS won't render subreport if it returns nothing.

The more easy solution is:
Sanjay Kumar Rajarao responded on 16 Oct 2013 12:15 AM Access sub report properties - visibility - show based on expression. Enter this
code:
=IIF(RowNumber(Nothing)>0,False,True)
https://community.dynamics.com/gp/f/32/t/114129

AnarchistGeek
Hello,
I had just run into this issue myself. The ugly error along the lines of "Error: Subreport could not be shown" was really annoying me.
Solution:
To solve this, I simply nested the subreport within a rectangle and used an expression on the visibility for that rectangle like so.
ex.
=IIF(Fields!Field1.Value IS NOTHING,true,false)
(Field1 in my case was a returned data column from the parent report.)
Make your changes accordingly :)

Related

Hide space between elements of a report

I have one report with various subreports. These subreports are within a table cell. When the subreport doesn't have any data available, I hide the components (tables, textbox, charts) in that subreport. However, this creates some blank space and I need to eliminate this space.
I already used the properties ConsumeContainerWhiteSpace and KeepTogether, but the blank space is still there.
Any suggestions to remove the blank space?
To hide or show an entire row based on another reports results will be difficult, if not impossible. You will need to get this data in your parent report somehow.
I would create a cut down version of your subreport's query that returns row count for every subreport, but within the parent report. Might look like this:
UserID RecordCount
Abby 3
Bob 0
Carl 1
If you are using SSRS 2008r2 you can then use a lookup function to set row visibility. For example the row visibility expression might be
=IIF(Lookup(Fields!UserID.Value,
Fields!UserID.Value,
Fields!RecordCount.Value,
"LookupDatasetName") > 0,
false,
true)
If an earlier version of SSRS, then join that dataset into the dataset for your table.

How can I get a field to print at the top of every page in JasperReports?

I am using iReport 3.7.6 to create this report.
I have a report based off of an XML file. There is a 2-column master report and it has a detail band with a subreport.
I have a field called "Name" in the subreport. I want it to print at the top of every page. Or even at the top of every column. I have tried virtually everything I know how to do.
"Print When Detail Overflows" doesn't work, because this setting is in the detail.
I sure hope I don't need to create a subreport for every report break I want. I'll have like 4 or 5 subreports.
Is there some way to determine when the page has changed, and then use that event in a "Print When" expression?
Here is one solution, presuming the value does not change between pages:
Write a query for a subreport that obtains only the Name value.
Change the dimensions of the subreport to be as small as necessary.
Place the subreport in the page header band of the master report.
To answer your question accurately, more details (such as pictures of what you have versus what you want) would be helpful.
you can use pageCount variable which is implicitly available in jasper reports to know whether the page has changed or not.

The engine showing only few rows in report - How to solve?

I have a problem with JasperReports' report. I want to create a report that produces for each Database entry, on sheet. When I create it, it shows me only a few rows. Maybe there is a parameter to set in the iReport designer.
A number of things to check:
Change the height of your report. Do you get more rows to appear? What about the height of your band? Does it change the results?
Check which band you have your content in. Some bands behave differently than others. Header/Footer/etc bands do not expand.
Check your input (the data from your query / xml datasource / whatever). Make sure that what you think is the input to your report really is.
Otherwise, likely we'll need more information. If you could upload an example jrxml that would help.

How to supress empty subreports in SSRS 2008

I'm creating a 'master' report in SSRS 2008 that collaborates other reports about a person. Sometimes not all of the other reports are relevant and as such return nothing. I'd like to be able to exclude this from the master report so it does not leave a blank page.
I'm aware of the 'no-rows-message' feature, but a whole page with simply "Not applicable for this person" is hardly the best solution!
Essentially I'm looking for a way to determine if a subreport is 'empty' and use that in a visibility expression.
Any help is most appreciated
OK, so I've got this figured now. The answer is to place the subreport into a rectangle. Then set the visibility of the rectangle to something like this:
=IIF(First(Fields![SOMEFEILD].Value, "[SOMEDATASET]") IS NOTHING, TRUE, FALSE)
Where [SOMEDATASET] is a dataset populated in the same way as the one populating the subreport. Then if the subreport is empty, then [SOMEDATASET] will also be empty, and more to the point, the field [SOMEFEILD] will be equal to NOTHING.
Bada-Bing! One report that is not cluttered with paper-wasting empty pages.
Note: there is one bad side-effect to this approach, in that, the SQL server will be sending the same information twice, once to populate the subreport's dataset, and again to populate the duplicate dataset in the report. For me, this is acceptable, others may want to be aware of this.
This solution worked for me as expected, eliminating the hyperlink to the subrepot. Within the «Action» menu in the section where you specify the subreport name:
=iif(fields!SomfieldName.Value <> Nothing, "YourSubReportName",Nothing)
Simple and easy solution!

Inclusion and exclusion of subreports (iReport-JasperReports)

I need to include or exclude a subreport based on a condition. I'm using iReport to create JasperReports. I.e., if a subreport has values, I need to include that subreport, otherwise not. Can anyone please send a sample or tell me how to resolve this.
you can in the master report get data from your data source that allows you to identify if the subreport should be included, then use the 'printWhenExpression' field on the subreport element to check that data.
I use this regularly - for example the printWhenExpression field may contain:
new Boolean($F{TOTAL_STATS}.intValue() != 0)
where TOTAL_STATS is from the master report's database query. If non-zero we show a subreport detailing some data.
From my knowledge, if there aren't any data printed in the subreport, Jasper eliminates the blank space. In other words, if your subreport would normally occupy half a page, but there is no data, then the empty space is eliminated. I'm not sure this is what you mean by including or excluding the report.
Another solution would be to place the subreport in the main report, and from right-click ->properties -> Subreport tab, you select the "Subreport condition" tab and write your condition there. If the condition is true, the content of the subreport will be printed, otherwise it won't be printed.
Jamie Love's answer about "printWhenExpression" is on target.
if there aren't any data printed in the subreport, Jasper eliminates the blank space
Actually, at least in JasperReports 3.7.0 there is a subreport property "Remove Line When Blank" that controls that behavior. By default - at least when I use iReport - that parameter is off.
WEG