SSRS - Export to Excel Should Execute a Second Dataset Only - reporting-services

I have two queries, one: fast query with few columns; second: with more columns (which is slow).
Now, I want the report to execute only the fast dataset/query with few columns so that the report will display output efficiently. Second slow query/dataset should not be executed at this level.
On clicking the Export to Excel button should execute the second slow query/dataset with all the columns and export only this output with all columns. But report with few columns should not be included in the exported excel output file.
Can someone please help ? ?
Thanks in advance.
Regards,

The easiest way to do this is to use the Globals!RenderFormat.
You can toggle the hidden property of the UI element related to the long running export based on the render format.
<YourExportData.Hidden>=IIF(Globals!RenderFormat.Name = "EXCEL", false, true)

Related

Hide field when export to CSV in SSRS with expression

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.

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.

MS Access: Command button to export a report to a CSV file

I was wondering if this was possible. I have my main form with a bunch of tables on it, and then I have a report. Standard stuff there. The report is named Report1. What I was wondering, is there a way I can put a command button on my main form, that when pressed, will export Report1 onto my desktop (or wherever I specify) in a CSV format? I would like to do this in VBA if possible. I'm not sure if I could make a macro format into CSV, but I am pretty open to any suggestions. Thank you
You can export the report's data to CSV by using DoCmd.TransferText with the report's Record Source table or named query.
Take a look at this: VBA DoCmd.TransferText - exporting query to .csv with user defined file path
A report is always based on a query.
You can find your query in the properties within the Design View of your report ("RecordSource").
The best way should be to generate a query (based on your current report) and link that query to the report ("RecordSource") and to the export button (DoCmd.TransferText).
Thereby, if you want to change your report / report data, you only need to change it once.

Access report prints multiple pages when text box control source is using a multi-value field from a table

The Access 2010 report i have has a text box that uses a multi-value field from a table for its control source. I know multi-value fields in tables are bad but its what i have to work with at the moment.
The problem i am having is that even though its only a two page report when i physically print it or do a print preview i get more then 2 pages. So if the multi-value field has (2) values i will get (4) pages total with the same information basically (2) copies.
How can i prevent the report from printing a copy for each value?
Ok so I will answer my own question now that i have found a work around.
I found a work around that will let me print only the pages i want (ie the first two pages or one copy not several)
In my macro instead of using RunMenuCommand PrintObject that just prints the report.
I created a vba function
Function cmdPrint()
DoCmd.PrintOut acPages, 1, 2 //acPages, start_page, end_page
End Function
and used this function from the macro using RunCode cmdPrint()
Now I only get one copy not several. Like I said its a work around but it works for me and i hope that it will help someone else someday with the same problem.