Recent Updates
Sphere of Care
Syndication
Reading/Listening
  • The Clarence Greenwood Recordings
    The Clarence Greenwood Recordings
    by Citizen Cope
  • Simple Genius
    Simple Genius
    by David Baldacci
Archives
« Error: 18456, Severity: 14, State: 16 | Main | Assigning Multiple Query Parameters to One Report Parameter »
Wednesday
18Oct2006

The Choose Function

I recently hit a wall when I needed to display one of three fields in a textbox based on a parameter value.  Of course, I could write custom code and write a function to use the SELECT CASE function but it seemed over kill and unmanageable for my simple options.  What would seem trivial in the .net languages suddenly seemed difficult in reporting services.

Where the immediate IF function IIF allows a condition and two paths of execution, what if you needed the functionality of a SELECT CASE with n branches of execution?

The Choose() function allows multiple conditional statements.  In this scenario, I had a drop-down list of All, Labor and Non-labor.  When the user selected All, I wanted to use the AllExecution column in my table but if they selected Labor or Non-labor, then I wanted to use the LaborExecution and NonLaborExecution columns instead.

The syntax for these options was pretty straight forward:

=Choose(Index as Double, Choice as Object, ...)

So the expression for my textbox in my table was:

=Choose(Parameters!LaborType.Value, Fields!Amt.Value, Fields!laborAmt.Value, Fields!nonLaborAmt.Value)

A word of caution

The Choose() function is not zero-based (like every other index in the .net framework).  Therefore, my values for the drop-down list had to be 1, 2 and 3 instead of 0, 1 and 2.

Reader Comments (1)

Getting this to you the easy way:

http://www.nbc.com/Video/rewind/full_episodes/heroes.shtml

All 11 episodes are there.
December 5, 2006 | Unregistered CommenterNysidra

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.