I am using SSRS 2012, and Excel 2010, I want to hide a column when Exporting to Excel, after looking through some of the forums it seems the best way to do this is by going to the Column or Text box of what you are looking to hide and under the Visibility/Hidden option set the Expression to be :
=IIF(Globals!RenderFormat.Name = "EXCEL",true,false)
I have tried this and for some reason it doesn't work, however if I reverse the options of true and false I can get it to hide the column in SSRS but it also hides this in Excel. Could this be an issue because of the version of Excel I am using?
In SSRS 2012 the XLSX export format was introduced, which uses a different renderer than XLS exports.
So I wonder if this is causing the issue. Modify the visibility statement to consider both export formats, something like:
=IIF(Globals!RenderFormat.Name = "EXCEL" or Globals!RenderFormat.Name = "EXCELOPENXML"
,true
,false)
This seems like a good first test.
Because you are returning a boolean you do not need the IIF:
=Globals!RenderFormat.Name = "EXCEL" or Globals!RenderFormat.Name = "EXCELOPENXML"
or this is also valid:
=InStr(Globals!RenderFormat.Name,"EXCEL") > 0
Related
I am working a report in SSRS. that has two sections one is graph and other is Table.
client should able to see both Graph and table on reporting manager but when exported only the table should get exported to excel. Please let me know how to achieve this.Please find the below screenshot. enter image description here
You can set the Hidden property of anything you want to hide to an expression. If you base this on the renderformat you can hide things depending on what format you export in.
This was introduced in 2008R2 so I'm assuming you are not using an earlier version.
Set the 'Hidden' property of the chart or it's container to
=NOT(Globals!RenderFormat.IsInteracive)
This should hide the chart when it's redndered to any other format.
Read this for more details
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/built-in-collections-built-in-globals-and-users-references-report-builder?view=sql-server-ver15
For the chart, you set the Hidden expression to not show if the format is Excel.
=IIF(Globals!RenderFormat.Name = "EXCELOPENXML", False, True)
I want to hide one field in SSRS when I export the report. I know that if I put NoOutput property it will work but I have one more expression that I want to put for field visibility. I have this expression for my visibility and works fine for Excel, PDF,...
=IIf(Parameters!Limited.Value=false,false,true)
But when I export to CSV this doesn't work.
How can I improve this so that it also works for CSV?
You have to remember that there are 2 types of exports in SSRS:
Data export - CSV and XML
Image based export - Word, PDF, Excel, TIFF, printing
The visibility property will only be read when you export to an image based export, and the data output property will only be read when using a data export.
If you can live with having the column there with the data being blank, then use Aldrin's method. If you want the column to not be there when exported and the columns you don't want to export is known in advanced, you're can use d b's way which is have 2 different tables, 1 for display but all the data is no output, the other output only for data export and visibility hidden.
If you need to do "No Output" dynamically, then that is pretty much impossible as a limitation of SSRS.
Put this script under Visibility property.
=IIF(Globals!RenderFormat.Name = "CSV", True, False)
or Just this
=Globals!RenderFormat.Name = "CSV"
It is not possible to conditionally hide a field for CSV output in SSRS.
But if it is very important to you, you can go through the trouble of creating 2 (or more) nearly-identical tables and show/hide the entire tables conditionally.
The contents of hidden tables (as opposed to rows and cells) do not get exported to CSV.
=IIF(Globals!RenderFormat.Name = "CSV", True, False)
This doesn't work.
The only option is to create as many reports with the different column combinations then load the correct one dynamically.
I originally thought this would be an easy task, but after several hours of research I'm reading there may be a SSRS bug when exporting hidden fields to CSV which doesn't make this possible?
What I'm looking to do:
I have a report with several columns (let's say 50). I have a parameter drop down for REPORT_VERSION that allows the user to select "Standard" (all 50 columns) or "Express" (only 10 columns). I've been able to display the 2 versions correctly, but when I export (the express version) to CSV it shows all of the columns (and or tablixs) and not what the results look like.
I've read about and tried:
If I create 2 tablix and hide one based on the parameter value, the export to CSV still shows both the visible and hidden tablix.
If I use =IIF(Globals!RenderFormat.Name="CSV", True, False) - this doesn't work for CSV output
Changing DataElementOutput = NoOutput. This hides the columns or table from the CSV output, but this can't be dynamically changed based on a parameter value.
Could this be done in the "custom code" section via vbscript??
Many of the articles and threads I read through dated back to 2010-2012 so hopefully there is a solution now? I'm really at a less here.
Help would be greatly appreciated. Thank you
I was able to get this to work in SSRS 2008 and 2012 based on your attempt #2. I created a dummy report with a data source query of
SELECT 'value1' as col1, 'value2' as col2
I then added the following expression to Column Visibility to column2
=IIF(Globals!RenderFormat.Name="CSV", False, True)
Note that the true and false are reversed from your sample. When the report was generated, column 2 was hidden, but when exported to CSV, column 2 was present.
To incorporate your parameter into the visibility expression, you could do something like this
=Switch(
Globals!RenderFormat.Name="CSV", False,
Parameters!REPORT_VERSION.Value = "Standard", False,
True, True
)
This will set the hidden property of the column to false if rendered as a CSV, or if "REPORT_VERSION" parameter is set to "Standard", else hide the column. This expression would need to be added to the Column Visibility of every column you want to hide in the "Express" version of the report.
EDIT
OK, I understand the issue now and can replicate it (I was backwards on the concept). You can explicitly set the visibly of a column to hidden and it won't show up in a CSV export. However, when you attempt to control this via an expression, the CSV export ignores this setting.
Data based exports look to be controlled by the "DataElementOutput" property. Setting this to "NoOutput" will suppress this that element from the CSV output. Unfortunately, it doesn't appear it can be controlled by an expression. Microsoft does not appear to have any plans to change this(https://connect.microsoft.com/SQLServer/feedback/details/431073/ssrs-programatically-controlling-the-dataelementoutput-property)
The Microsoft connect request hints at creating two tablixes and filtering out all the results for each one based on the parameter supplied (i.e. "Express" or "Standard"), additionally hiding the other tablix based on the parameter value. I tried this and it worked halfway. Although the other tablix had no results, it would still export the column headers and one blank row.
Now I'd be curious to know what a good solution would be to this issue.
There are 7 built in options for exporting SSRS 2008 reports.
I was wondering if there is an easier way to code the following in SSRS when chosing the export option:
=IIF(Globals!RenderFormat.Name="WORD" OR Globals!RenderFormat.Name="XML" OR
Globals!RenderFormat.Name="CSV" OR Globals!RenderFormat.Name="TIFF" OR
Globals!RenderFormat.Name="PDF", Globals!RenderFormat.Name="MHTML" OR
Globals!RenderFormat.Name="EXCEL",true,false)
Is there a way to write the code above without having to list each export option listed? A way that includes all the export options? If so, how would you write that code?
The suggestion from ShellNinja won't work as a visibility expression because of the order in which expressions and other report items are processed and rendered.
The article Built-in Globals and Users References on TechNet hints at this (allbeit a very vague hint) under the RenderFormat subheading where it says that:
Globals!RenderFormat.Name is available during specific parts of the report processing/rendering cycle.
Globals!RenderFormat.Name is not populated prior to expressions being evaluated, it's populated on completion of the current render request which is why it can't be used in a visibility expression but will display the name in a textbox.
Globals!RenderFormat.IsInteractive is populated prior to expression evaluation and is the only way of hiding/showing a report item prior to a report being rendered. RPL and HTML are considered fully interactive formats, all other formats are not or only support some interactive features. More information on this can be found in the article Comparing Interactive Functionality for Different Report Rendering Extensions on TechNet.
Use "RPL" for a simpler IIF expression so that any other format is "EXCEL", "CSV", "WORD", etc. When the report is displayed in the report server viewer or a ReportViewer control the RenderFormat is "RPL".
=IIF(Globals!RenderFormat.Name = "RPL", true, false)
The above code when set as a visibility expression will show the field when rendered in SSRS and hide it on export.
Tip: When you have a long IIF expression use a switch expression Reporting Services Expression Examples they are by far cleaner and easier to manage.
The expression below, placed in the Column Visibility dialog box for a selected column, displays the column only when the report is exported to Excel; otherwise, the column is hidden.
=IIF(Globals!RenderFormat.Name = "EXCELOPENXML" OR Globals!RenderFormat.Name = "EXCEL", false, true)
This is mentioned in the MSDN itself. Hence it does work!
This is 2008R2. I have a dataset with a query "DESIGN" on a database with results for a export format like this:
| pdf | true |
| rdl | false |
| excel | true |
My Goal is to change the visibility depending on the export format of the report. The property of the visibility can be changed in the Database, so I need it to be dynamic. If I export to pdf, a specific textbox or tablix should hidden... I tried Lookup on a separate textbox which gives me the RenderFormat. And used the expression in the Hidden-property.
=Lookup(ReportItems!Textbox1.Value
, Fields!RenderFormat.Value
, Fields!Hidden.Value
, "DESIGN")
I also tried it with 1 and 0 values in the database and converted it to CBool(...) but it appears to be a bug or something like that, because the value of the Textbox1 just disappears when the report is rendered. So there is no possibility for the Lookup to work.
With Globals!RenderFormat.Name instead of ReportItems!Textbox1.Value it is not working either...
It would be great if you could help me!
There can also be an easier way... if you know it... Thank you!
Found it!!! A solution to the problem is the following:
1) First I have to create some VB-Code: Rightklick beside the ReportBody to open the ReportProperties. Than the following Code should be used to create a valuetype string variable:
Public Shared Dim rf as String
Public Function Setrf (ByVal var as String)
rf = var
End Function
2) A TextBox should be added to fill the variable. The TextBox expression should be:
=Code.Setrf(Globals!RenderFormat.Name)
3) The Tablix Propertie Hidden should get the following Lookup expression refering to the Code:
=Lookup(Code.rf,
Fields!Reporttyp.Value,
CBool(Fields!LegendeVersteckt.Value), "Design")
This is for the case of true and false being 1 and 0. Now on differen export Format it is Hidden or not. :)
I was hoping this would be as simple as using a report parameter which could then be fed into the WHERE clause of your query. However, parameters aren't allowed to use the Globals!RenderFormat.Name field (I don't know why). I'm not sure about how to use a lookup expression to pull back this as you asked for, but I used the following nested IIF function to toggle visibility in the Hidden expression of a textbox based on rendered format:
=IIF(Globals!RenderFormat.Name=nothing,true,
IIF(Globals!RenderFormat.Name="EXCEL",false,
IIF(Globals!RenderFormat.Name="PDF",false,true)))
As you were going to have a single query that holds the boolean visibility values anyway, this option may not be bad. The only problem will be maintaining it in the many different locations you probably need it. I would recommend storing it in a hidden textbox and then copying and pasting from that as needed so you have one place where you change the function and you don't have to worry about typos but once.
In my testing, I found that the Render Formats are case-sensitive, and that for the report viewer rendering, the format name is RPL, not rdl.
The most comprehensive list I could find of Rendering Formats in correct case is below and came from here: http://msdn.microsoft.com/en-us/magazine/cc188712.aspx
HTML3.2
HTML4.0
HTMLOWC
MHTML
IMAGE
EXCEL
CSV
PDF
XML
I know it's not exactly what you wanted, but hopefully it helps.