Hide field when export to CSV in SSRS with expression - reporting-services

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.

Related

Hide fields in SSRS report based on expression

i have one problem with exporting to CSV format. In my report i user parameter to hide on field and it's working ok except for exporting in CSV format.
Column visibility is see like this:
=IIF(Parameters!ShowBonusLockingData.Value="False",true,false)
but this doesn't work in CSV. Can someone help me with this problem. Setting column property to NoOutput is not a solution, because that property never shows the column then

SSRS 2008 R2 Bug? Still? Dynamically hiding column or tablix and exporting to CSV

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.

Show less data on the Report but while Exporting the data in excel , export more data

I need to show only 5 rows of data on the SSRS reports , but when the user exports the data he must be able to export all the data that dataset is holding. Is there anyway to achieve this ?
In Group Properties > Visibility, select Show or hide based on an expression and set the expression to:
=IIF(RowNumber("DatasetName") > 5 AND Globals!RenderFormat.IsInteractive, True, False)
RenderFormat.IsInteractive returns true for report viewer preview or HTML view, so you should only see 5 rows in these views while seeing all rows when exporting to another format. You could also optionally substitute in Globals!RenderFormat.Name = "EXCEL" if you want to target a specific export format.

SSRS 2008 Stop Tablix from Exporting to CSV

I have two Tablix controls on my SSRS report. I want one of them to export and one not to export. I have accomplished this by setting the hidden property on the one I want to export to:
"=Globals!RenderFormat.IsInteractive = True"
and the one I do not want to export to:
"=Globals!RenderFormat.IsInteractive = False"
This works perfectly when I export to Excel, however CSV simply ignores these values and exports both Tablix controls. I need to know how I can force CSV to only export one Tablix control.
Format options such as expressions on visibility are ignored for CSV rendering methods. CSV rendering methods are essentially data flows, so you can suppress elements that you don't want to include in CSV files by changing the DataElementOutput from Auto, the default value, to NoOutput.
You can't conditionally set the DataElementOutput, but you can conditionally set the tablix filters. That will leave the header row in the csv output, but trims the data rows.
Try setting the visibility.hidden property of the tablix you don't want to export to CSV to:
=(Globals!RenderFormat.Name = "CSV")
http://blogs.msdn.com/b/robertbruckner/archive/2010/05/02/globals-renderformat-aka-renderer-dependent-report-layout.aspx

SSRS: Conditionally hiding columns based on parameter values - CSV export ignores

I have a simple table based report in SSRS 2008, There are 10 columns and each column has a corresponding parameter to determine whether the column should be shown. I achieve this by setting the Column Visibility option you get when right clicking on the column header in design mode. In my case I choose to 'Show or Hide based on an expression' to which I set the expression to the value of a parameter which is a boolean type.
The functionality works as expected during the initial render however when I choose to export the report to CSV the visibility expression is either ignored or not evaluated because the columns show up regardless of the setting.
The visibility dialog has three options, Show/Hide/Show Or Hide based on expression - If I explicitly set Hide option the CSV export does not include the column as you would expect however if I use an expression it will - I even went so far as to make the expression explicit like '=True' and still it was ignored.
How do I get the export option to evaluate this properly?
Here's a solution by KarenH in the article Hide/Show Items Dependant On Export Format
Basically, you can set the DataElementOutput = NoOutput on the control you want to hide.
This worked for me to hide tables when exporting to CSV.
You cannot hide or omit columns for the export, using expressions. This is because the expressions will only get evaluated in the report itself, not the export.
a workaround would be to hide the columns by default and show all others using the expression.
my apologies, that above statement made no sense. It seems what you will have to do is make a parameter that will show which columns to hide or display, then when the report runs just don't display any data in those columns. You can also change the value of the column heading based on these parameters.
The only other option is to create as many reports with the different column combinations then load the correct one dynamically.
I believe this may be a bug. I have used the Reporting Services export with hidden columns dependant on a parameter at runtime. If I run the report with the columns hidden and then export the result to Excel or PDF or most exports formats the hidden columns are NOT exported. If I export the report to a CSV file, the hidden columns ARE exported. Surely this is a bug in the CSV export.
Logically they should all behave in the same way.