SSRS - Naming Excel Tabs based on Page Number/Contents - reporting-services

My SSRS Report has two 'pages'.
The first page [run time] shows a Text Box with the Criteria used for returning data.
The next page[s] has all the data.
I have given the Tablix Member for the Data pages the Page Name of 'Detail'.
When the report is exported to Excel, it is displayed on two Sheets.
The first Sheet [with the Criteria] is named "Sheet1".
The second Sheet [with all the Detail Data] is named "Detail" - which is how I want it.
How do I get the First Sheet [... currently being named "Sheet1"] to be named 'Criteria' when it is exported to Excel?
Can I use an Expression somewhere that says something like this:
IIf (PageNumber = 1, "Criteria", "Detail")
?
Thanks in advance!!

You don't actually need a conditional expression for this. You can use the PageName property to control the sheet names. You can give each table a separate page name. If there are no tables on the first page, insert a rectangle and give that a page name. In the Report properties there is also an InitialPageName you can use for the first page. Lastly, make sure that you do have a PageBreak defined, don't just let it roll over to the next page based on the height.

Related

How can I append the results of additional queries to an SSRS report?

I am generating an SSRS report whose results are displayed like so:
I need to append similar query results (same exact query, one different parameter value) to the right of this data, so that one additional result set of data (from a 2nd query) would look something like this (but with different data, of course - this is just copied-and-pasted to show what's needed):
How can I add multiple of these similar-but-distinct result sets so that they can be read from left to right as shown above?
Solution: COLUMN GROUPING
If I have understood your question correctly, you are expecting to show those 3 columns repeatedly for different set of values. All you need to do is put those 3 columns in a group (Column Group) and Group by on whatever "Field/Parameter" you want to it repeat. Let me know how it goes!!
Based on what is written here, this is how I accomplished this:
I created a new report based on the existing one, and then added a Subreport and then dragged the existing (original) report onto it (I dragged "VariancePricebyProduct_Facelift.rdl" onto the subreport in "VariancePricebyProduct_Facelift_WithSubreports.rdl"). Then I selected the context menu item "Subreport Properties" and added a parameter ("Unit"), providing it with a "hard-coded/baked-in" value ("CHOPHOUSE") different from the one to be provided by the user for the main report.
Then, since I want to keep the same date values from the existing report, I added two more parameters to the subreport and set them to use the same values for the date range as those used there in the main report by selecting the "formula" ("fx") button and 2-clicking the appropriate parameter to be used as the passed-in (tramp) value:
That works. Just to make it plainer, here is how it looks at design time:
The mess at the top is "VariancePricebyProduct_Facelift.rdl"; the bit below is a Textbox/Label for the subreport and then the subreport itself.
And here is how the data looks where the original/base report finishes and the subreport begins:

Show a message to the user instead of blank report [duplicate]

I am building an SSRS 2005 report using BIDS. My report filters on date. When the selected date returns no data rows the report is blank, just the title is displayed, no table or column heading.
How can I change this to display a message like No data available. or Report is empty.?
You could set the property NoRowsMessage available on the report's table control like this:
Select the Tablix control and press F4 to view the Properties pane.
Find the NoRowsMessage property and set the value to whatever message you'd like.
You can also to format the message using the Font and TextAlign properties.
Here are some examples of what the report will look like under various settings:
Further Reading: Here is a Technet article on how to Set a No Data Message for a Data Region
Avoid NoRowsMessage and build your own conditional empty row
One problem (or feature if that's what you want) with NoRowsMessage is that it'll literally replace the entire table with just a plain old message string.
Which provides a relatively counter-intuitive end user experience in my opinion. Normally when no data is found by a system, we'd like to know something about what data was being looked for and what it would have looked like.
Instead, based off how to keep the structure of the Tablix when there is no data to show, you can do the following:
Insert New Header Row, outside the group and above the details record.
Right click on the side of the new row and Set Row Visibility
Set Visibility to the following expression which will count the rows inside the current Tablix and only set Visibility to True if there is no data.
=CountRows() > 0
Optionally, merge the cells and add your own message or just display an empty row
Here's a comparison of how the various options will render: (pick whichever look you think best fits your data and use case)
Right-click on whatever databound element(s) you are using in the report and there should be a property NoDataMessage There are a host of options there but the Caption is the first element I would look at.

Naming sheets in SSRS when imported to Excel

I have put page breaks in my SSRS report. When report imported to Excel, report is divided into different sheets according to page breaks. Is it possible somehow name those sheets? Thanks for assistance.
You can easily change the tab name by setting the "Page Name" field on the properties sheet of the group (in this example "Buyer") that is providing the page break.
You can't do that with standard SSRS, but I know you can do it with OfficeWriter by SoftArtisans.
It's a proprietary application which isn't cheap, but it let's you create a template in Excel which you can then export the report into. You can do stuff like create charts and pivot tables as well which get populated automatically.
We have used their product and it works well. Their app can also be used to generate other Office artifacts such as Word docs.
(BTW I have no affiliation with SoftArtisans)
But how can I Name each tab with different names?
As Randy pointed out, the PageName is used to name tabs when a report is exported to Excel. Normally you would use a field name for the PageName expression.
If your page breaks are due to a Group, you would probably want to use the name of the group as the PageName. For instance, if you had a report of sales by customer with a separate tab for each customer, you would probably want to use the customer name field as the PageName expression.
=Fields!Customer_Name.Value
If you add the left(buyer,5) etc..into your dataset, put this as the initial group in your report then (page break between each instance of a group) and also use this field as the page name..should do the trick
Navigate to the tablix properties. Type the "SheetName" you need under "PageName" expression. It is better to assign this property from a Global variable, but if you need a custom set name for each of your Excel tabs, this is the way.

How do I display 'No data available.' when there are no rows to show on the report?

I am building an SSRS 2005 report using BIDS. My report filters on date. When the selected date returns no data rows the report is blank, just the title is displayed, no table or column heading.
How can I change this to display a message like No data available. or Report is empty.?
You could set the property NoRowsMessage available on the report's table control like this:
Select the Tablix control and press F4 to view the Properties pane.
Find the NoRowsMessage property and set the value to whatever message you'd like.
You can also to format the message using the Font and TextAlign properties.
Here are some examples of what the report will look like under various settings:
Further Reading: Here is a Technet article on how to Set a No Data Message for a Data Region
Avoid NoRowsMessage and build your own conditional empty row
One problem (or feature if that's what you want) with NoRowsMessage is that it'll literally replace the entire table with just a plain old message string.
Which provides a relatively counter-intuitive end user experience in my opinion. Normally when no data is found by a system, we'd like to know something about what data was being looked for and what it would have looked like.
Instead, based off how to keep the structure of the Tablix when there is no data to show, you can do the following:
Insert New Header Row, outside the group and above the details record.
Right click on the side of the new row and Set Row Visibility
Set Visibility to the following expression which will count the rows inside the current Tablix and only set Visibility to True if there is no data.
=CountRows() > 0
Optionally, merge the cells and add your own message or just display an empty row
Here's a comparison of how the various options will render: (pick whichever look you think best fits your data and use case)
Right-click on whatever databound element(s) you are using in the report and there should be a property NoDataMessage There are a host of options there but the Caption is the first element I would look at.

How to get named excel sheets while exporting from SSRS

Whenever a single page report is exported to excel, sheet in excel is named by the report name.
If a report has multiple pages, the sheets are named as sheet1, sheet2,....
Is there any way to specify sheet names in SSRS 2005 ?
solution:
Found this after some googleing:
Changing the Sheet names in SQL Server RS Excel: QnD XSLT
Will try out and post an update if it works.
Necromancing, just in case all the links go dark:
Add a group to your report
Also, be advised to set the sort order of the group expression here, so the tabs will be alphabetically sorted (or however you want it sorted).
'Zeilengruppe' means 'Target group'
'Gruppeneigenschaften' means 'Group properties'
Set the page break in the group properties
'Seitenumbruche' means 'Page break'
'Zwischen den einzelnen Instanzen einer Gruppe' means 'Between the individual instances of a group'
Now you need to set the PageName of the Tablix Member (group), NOT the PageName of the Tablix itselfs.
If you got the right object, if will say "Tablix Member" (Tablix-Element in German) in the title box of the properties grid. If it's the wrong object, it will say only "table/tablix" (without member) in the property grid's title box.
Note: If you get the tablix instead of the tablix member, it will put the same tab name in every tab, followed by a (tabNum)! If that happens, you now know what the problem is.
To export to different sheets and use custom names, as of SQL Server 2008 R2 this can be done using a combination of grouping, page breaks and the PageName property of the group.
Alternatively, if it's just the single sheet that you'd like to give a specific name, try the InitialPageName property on the report.
For a more detailed explanation, have a look here: http://blog.hoegaerden.be/2011/03/23/where-the-sheets-have-a-name-ssrs-excel-export/
In SSRS 2008 R2 use PageName property of page group:
http://bidn.com/blogs/bretupdegraff/bidn-blog/234/new-features-of-ssrs-2008-r2-part-1-naming-excel-sheets-when-exporting-reports
To add tab names while exporting to excel, I used the following method:
On the report design window, select the tablix object.
Open properties window of the tablix object.
Add the required tab name to the PageName property.
Run the report
Export the report to Excel.
Now the worksheet name is the same as the PageName property of the tablix object.
Put the tab name on the page header or group TableRow1 in your report so that it will appear in the "A1" position on each Excel sheet. Then run this macro in your Excel workbook.
Sub SelectSheet()
For i = 1 To ThisWorkbook.Sheets.Count
mysheet = "Sheet" & i
On Error GoTo 10
Sheets(mysheet).Select
Set Target = Range("A1")
If Target = "" Then Exit Sub
On Error GoTo Badname
ActiveSheet.Name = Left(Target, 31)
GoTo 10
Badname:
MsgBox "Please revise the entry in A1." & Chr(13) _
& "It appears to contain one or more " & Chr(13) _
& "illegal characters." & Chr(13)
Range("A1").Activate
10
Next i
End Sub
There is no direct way. You either export XML and then right an XSLT to format it properly (this is the hard way). An easier way is to write multiple reports with no explicit page breaks so each exports into one sheet only in excel and then write a script that would merge for you. Either way it requires a postprocessing step.
I was able to get this done following more complex instructions suggested by Valentino Vranken and rao , but here is a more simple approach , for a more simple report . This will put each table on a separate sheet and name them in Excel . It doesn't seem to have an effect on other exports like PDF and Word .
First in the Tablix Properties of of your tables under General , check either Add a page break before or after , this separates the report into sheets .
Then in each table , click the table , then in the Grouping view , on the Row Groups side , select the parent group or the default row group and then in the Properties view under Group -> PageBreak set BreakLocation to None and PageName to the sheet's name .
The Rectangle method
The simplest and most reliable way I've found of achieving worksheets/page-breaks is with use of the rectangle tool.
Group your page within rectangles or a single rectangle that fills the page in a sub-report, as follows:
The quickest way I've found of placing the rectangle is to draw it around the objects you wish to place in the rectangle.
Right click and in the layout menu, send the rectangle to back.
Select all your objects and drag them slightly, but be sure they land in the same place they were. They will all now be in the rectangle.
In the rectangle properties you can set the page-break to occur at the start or end of the rectangle and name of the page can be based on an expression.
The worksheets will be named the same as the name of the page.
Duplicate names will have a number in brackets suffix.
Note: Ensure that the names are valid worksheet names.
You could use -sed- and -grep- to replace or write to the xml header of each file specifying your desired sheet name, e.g., sheetname1, between any occurrence of the tags:
<Sheetnames>?sheetname1?</Sheetnames>
While this usage of the PageName property on an object does in fact allow you to customize the exported sheet names in Excel, be warned that it can also update your report's namespace definitions, which could affect the ability to redeploy the report to your server.
I had a report that I applied this to within BIDS and it updated my namespace from 2008 to 2010. When I tried to publish the report to a 2008R2 report server, I got an error that the namespace was not valid and had to revert everything back. I am sure that my circumstance may be unique and perhaps this won't always happen, but I thought it worthy to post about. Once I found the problem, this page helped to revert the namespace back (There are tags that must also be removed in addition to resetting the namespace):
http://beatheadagainstwall.blogspot.com/2011/03/invalid-target-namespace-when-deploying.html?showComment=1440647962263#c5741523651495876761