Hide/Show Items Dependant On Export Format (SSRS)

Now and then I encounter forum questions in the style of the following:

I have a report with a title.  When rendered through the Report Manager and when exported to PDF, I want it to render as normal.  However, when exported to Excel I do not want to get the title.  How can I hide it?

Because I don’t like re-inventing the wheel each time I decided to write a blog post about it.

As of SQL Server 2008 R2, we’ve got a built-in global field that can help us out.  This field is called Globals!RenderFormat.  It has two properties: Name and IsInteractive.  Name represents the unique name that indicates the chosen renderer, and IsInteractive indicates whether or not the chosen report format is, well, interactive.

Depending on the renderer, the values of the properties differ.  To be able to use the variable in an expression, we need to know its values for each rendering format.  Here’s the list of different possibilities:

Renderer RenderFormat.Name RenderFormat.IsInteractive
Preview in BIDS or rendered through Report Manager RPL True
XML file with report data XML False
CSV (comma delimited) CSV False
TIFF file or Print button IMAGE False
PDF PDF False
MHTML (web archive) MHTML True
Excel EXCEL False
Word WORD False

If these names for RenderFormat look familiar to you, you’re probably right.  Have a look at the rsreportserver.config file in the C:\Program Files\Microsoft SQL Server\MSRS10_50.SQL2008R2\Reporting Services\ReportServer folder.  Note that you may need to adapt the folder to your specific settings.  In my case my instance is called “SQL2008R2”.  Near the bottom of that configuration file you can find the <Render> node, located under <Extensions>.  The names that you see there are those used by the RenderFormat.Name property.

Now that we know what values to test on, let’s get started.

If we get back to the example of hiding a title, or textbox, when exporting to Excel, here’s what needs to happen.  Locate the Hidden property of the textbox that you want to hide, and give it the following expression:

=IIF(Globals!RenderFormat.Name = "EXCEL", True, False)

What we’re saying here is: if the RenderFormat is EXCEL, then the Hidden property should be set to True.  Which results in a hidden textbox whenever the report is exported to Excel!

As Erik pointed out in the comments, in this particular case you don’t need the IIF() statement.  The result of the expression results in True when the expected value should be True, and False when False is expected.

As a quick note: when building your expression through the expression builder, you’ll notice that the Intellisense doesn’t know the new RenderFormat field yet.  Do not worry about that, just continue typing and ignore any errors being indicated.  If you use the syntax as I highlighted above, it will work!  Well, unless you’re running an earlier version than SQL Server 2008 R2 of course.  In that case it won’t work.

Intellisense doesn't know RenderFormat yet

In contradiction to the Intellisense, the bottom part of the expression builder screen has been updated to show the new properties.  So if you don’t remember the syntax, you can just locate the field in the Built-in Fields category and give it a good double-click.

RenderFormat is located in the Built-in Fields category

Of course, the Excel example in this post is just one of many possibilities that this new field offers.  Is your company environment-friendly and does it want to prevent wasting paper?  Now it’s possible, just hide that 50-pages long table when the report is being rendered for print!

Have fun!

Valentino.

References

Globals!RenderFormat aka Renderer Dependent Report Layout by Robert Bruckner

Share

Tags: , , ,

  1. Erik Eckhardt’s avatar

    Why would you wrap a Boolean-returning expression in an Iif() function?

    Any time you catch yourself writing Iif(Expression, True, False) go back and remove the Iif:

    =Globals!RenderFormat = “EXCEL”

    That’s already True or False.

    Reply

    1. Erik Eckhardt’s avatar

      That is… `Globals!RenderFormat.Name`

      My apologies. Anyway, this was helpful. Thanks for the blog post.

      Reply

    2. Valentino Vranken’s avatar

      Good remark Erik, in that particular case you indeed do not need the IIF statement!
      Well found :-)

      Reply

  2. Mike Michalicek’s avatar

    Thanks much for this information.

    I do have 1 question.

    I need to add a row to an Audit Log table every time a user runs a report, prints a report or exports a report. I also need to make a distinction between printing and exporting a report. I noticed that the TIFF export and the Print button have the same Render Format name and IsInteractive values. Is there any way to distinguish between printing a report and exporting to a TIFF file?

    FYI, I am using a custom assembly to call a WCF service which is used to cut the audit record.

    Reply

    1. Tony Bater’s avatar

      Mike, You don’t need a custom assembly to audit report execution. Check out the view ExecutionLog3 in the ReportServer database (the latter may be ReportServer$InstanceName)n on the SSRS host server. This view has rows for each execution of the report and includes much usefult information including user, execution time, duration parameter values etc. One of the fields is ‘Format’. The values here are similar to the RenderFormat.Name values, except that printing the report logs a value of ‘IMAGE’. That shoud give you all you need for your audit.

      Reply

  3. ganesh’s avatar

    Some time , we don’t know exact capabilities of any function.
    Thanks for exploring that….

    Reply

  4. Lupe’s avatar

    PDF export doesn’t support toggling. I tried the above Is Interactive to show or hide the tablix and still no luck. The goal is to have everything hidden when it is interactive and shown when its not.
    Any suggestions on how to get around this issue ?

    Reply

  5. Tony Bater’s avatar

    Lupe, have you tried setting the hidden property of the tablix to =Globals!RenderFormat = “PDF”?
    With that settin, the tablix should be visible under all formates except PDF.

    Reply

  6. Ed’s avatar

    Have any alternatvie for SSRS 2005 ¿?

    Reply

    1. Valentino Vranken’s avatar

      Wow erm, didn’t think so… Same for 2008 btw, the RenderFormat field only exists since 2008 R2.

      Reply

  7. canon ink’s avatar

    There are some important alternative for SSRS 2005.

    Reply

  8. Darren’s avatar

    I’ve tried Hidden=(Globals!RenderFormat.Name = “RPL”) on SSRS 2008R2 and it renders on view (preview in BIDS and on server) and export.

    Is there a reason why this would not work? Config or setting?

    Reply

  9. Sunil’s avatar

    What are the alternatives for SSRS 2005 to achieve this feature.

    Reply

    1. Valentino Vranken’s avatar

      In 2005 (or even 2008 – not R2) it’s not possible to automatically detect the render format. The only possibility that I see to get something as close as possible to the RenderFormat property is to implement an additional parameter on the report. This parameter then indicates what “format” is expected and depending on the selection you can show/hide items. You don’t necessarily need to implement the parameter exactly the same as the RenderFormat of course. Depends a bit on the situation, but a parameter of type boolean called “Include details?” could already be useful for a report that should come in two versions: high-level or detailed.

      Reply

  10. satish’s avatar

    Hai To All,

    Please Help me Out.

    Iam using SSRS 2008.my question is iam writeing make,model,year in single text box,but my intention is it is splitting into 3 columns seperatly (In CSV version).

    URGENT.

    Reply

    1. Valentino Vranken’s avatar

      Try this: add an additional tablix to your report, with those three columns as needed when exporting to CSV. Set the tablix to Hidden when not rendering as CSV. Set the existing textbox to Hidden when exporting to CSV. That should accomplish your goal.

      Reply

  11. satish’s avatar

    Thanks for ur reply.

    can u give any example for this…my goal is single textbox i use 3 columns( fields) .but when i export into CSV the column names are splitted into seperately.for example we are using 3 fields in a text box but when export into csv version it should split into 3 columns .Is it possible ?

    ex:
    name district region
    state
    country

    assume it as expected output :name district state country region

    when iam exported into CSV version.

    Note:district,state,country as take as single textbox(must and should)

    Reply

    1. Valentino Vranken’s avatar

      Hi Satish,

      Would you mind posting the question on a forum and then post a link to it here? That gives me the possibility to add a sample attachment and get some points meanwhile :) I ensure you to come back with a working example.

      Have a look at my About page (Community Activity chapter) for a list of forums on which I’ve got a profile.

      Thanks,
      Valentino.

      Reply

  12. satish’s avatar

    Hi Valentino,

    where should i post my example? i see ur blog ..good.really much appreciated for ur response.please give me concern.i have a sample example also.

    Thanks,
    Satish

    Reply

    1. Valentino Vranken’s avatar

      Hi Satish,

      The Microsoft forum will probably be easiest: http://social.msdn.microsoft.com/Forums/en/sqlreportingservices/threads/

      Don’t forget to post the direct link to your question here, I’ll reply promptly.

      Valentino.

      Reply

  13. satish’s avatar

    Hi Valentino,

    Link:

    http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/8ffe3513-d38e-4abe-bc51-75ea38729a23

    I posted my question in MSDN.Please give me answer as early as possible.iam waiting for ur reply.

    Thanks,
    Satish

    Reply

  14. kumar’s avatar

    Hi Valentino,

    What is the main difference between SQLSERVER 2005 and 2008 ,2008R2.give me best 10 differences.

    Thanks,
    Kumar

    Reply

  15. Rob’s avatar

    Hi,

    I get this to work for PDF and EXCEL, but it does not work for CSV.

    works just fine:
    Globals!RenderFormat.Name = “EXCEL”
    Globals!RenderFormat.Name = “PDF”

    does not work:
    Globals!RenderFormat.Name = “CSV”

    Any ideas?

    Thanks,
    Rob

    Reply

© 2008-2013 A Developer's Blog All Rights Reserved