Home > Uncategorized > SSRS #73 – Use Calculated Field to Dynamically Set Default for Parameters

SSRS #73 – Use Calculated Field to Dynamically Set Default for Parameters

Calculated Field has existed in Reporting Services since version 2005. SSRS 2005 did not have the most attractive user interface design, so this pretty useful feature stayed hidden from me until version 2008.

Even in SSRS 2008, I did not pay much attention to it until I started to write reports in MDX queries on SSAS cubes.


Once I started using them, I find myself like it more and more.

One of the challenges in SSRS reports is to set parameter defaults dynamically. It’s an even bigger challenge if you want to dynamically set parameter defaults to multiple values, such as (Select All). Don’t read this statement wrong. Setting parameter defaults to multiple values, such as (Select All), is not hard. What is hard is to do it dynamically, meaning the situation where you want to set the default or not depends on the selection of another parameter.

I recently ran into this issue when working on a Data-Driven Subscription project. The idea is that we’d use just one SSRS report for both online ad-hoc reporting, and for a daily data extraction that can be sent to users via E-Mail.

For the online ad-hoc reporting, we certainly do not want to default all parameters to (Select All). For the daily data extraction though, that’s exactly what we’d like to do.

Since I am using Data-Driven Subscription and a SSIS package to trigger the subscription, you would think that I can manipulate the parameter defaults in either SQL code and/or in SSIS scripting. But I highly recommend against that if your goals are

1) To use just one SSRS report for both online ad-hoc reporting, and for a daily data extraction

2) Not to replicate all the queries you already have in the SSRS report

3) Not to waste your valuable time to wrestle with Reporting Services. When it comes to parameters with defaults or cascading parameters, Reporting Services is not very forgiving in terms of dynamic settings. If you have tried that before, you probably know what I meant.

Using Calculated Field feature in SSRS 2005 and above is what I’d recommend.

Suppose you have a hidden parameter, Subscription.


Parameter Subscription has two values, 1 and 0.


Its default is 0 (not the 1 shown).


When Subscription is 1, we want to set the default of parameter Geography to (Select All).

We’d create a Calculated Field for DataSet_Geography. Call it GeographyKey_Dynamic.


In the Expression Editor for GeographyKey_Dynamic, enter an IIF() expression. This expression will basically use the GeographyKey value if the Subscription is 1, otherwise, it will be Nothing.


Now we are ready to use this new Calculated Field GeographyKey_Dynamic as the default value for parameter Geography.


DataSet_Geography is the same dataset for Available Values. The only difference is that in Available Values, we’d always use GeographyKey, which is a SQL column. For the Default Values, we’d use GeographyKey_Dynamic instead.



1) Watch out when you like the Calculated Fields too much and use them excessively. SSRS reports will typically go through Retrieval, Processing and Rendering phases during run time. If you have queried a Report Server database, you will find that the Processing and Rendering phases take more time than you’d like. Having too many Calculated Fields will no doubt increase the Processing time. So think about distributing the burden across queries on servers and calculations in memories.

2) For data-driven subscription, see my blog at

SSRS #60 – Steps to implement a data-driven subscription

  1. Richard Chess
    January 14, 2014 at 5:20 pm

    I am trying to do something similar where I’m using one parameter to drive the beginning and end date parameters. The problem I have is the subscription isn’t automatically rolling the dates forward after each run.

    Is there a preferred method to make the parameters automatically recalculate when the subscription is executed? The parameter expression is working correctly when the report is run adhoc or the 1st time the subscription is created.

    Examples for beginning date parameter default that I have tried:

    Example 1 – =IIf(Parameters!ReportType.Value=”D”, DateAdd(“d”, -1, Today), IIf(Parameters!ReportType.Value=”PM”,Today.AddDays(1- Today.Day).AddMonths(-1), Today.AddDays(1 – Today.Day)))

    Example 2 – =Switch(Parameters!ReportType.Value=”D”,DateAdd(“d”, -1, Today),Parameters!ReportType.Value=”PM”,Today.AddDays(1- Today.Day).AddMonths(-1),
    Parameters!ReportType.Value=”CM”,Today.AddDays(1 – Today.Day))


  2. Manuel Müller
    January 15, 2014 at 8:34 pm

    I’ve stubled across this post while trying to dynamically set default values from a query using the same dataset like the one used for available values. This post didn’t help my but finally found a way to manage it all. To help the rest of the world – her is how it’s made:



  3. Richard Chess
    January 27, 2014 at 4:46 pm

    Thank you for the response and I’ll give this try on my next report.


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: