RDL Reports: Tips, Tricks and Limitations

RDLWhen designing an RDL report for zenon Analyzer or Report Viewer, there are some questions that might arise:

  • Can timestamps be converted from localtime to UTC and vice versa?
  • How can units be applied to numeric fields in tables?
  • Are there any limitations when using dynamic property values for elements?

Here are the answers to those questions.

Timestamp conversion

The good thing is, that the datetime object in RDL is effectively the datetime object of the .NET Framework, which means that the methods “ToLocalTime” and “ToUniversalTime” are available. So the only thing that needs to be done is to ensure that the object before conversion is a datetime object. Here are some samples:

//converst report parameter “From” from local time to UTC
CDate(Parameters!From.Value).ToUniversalTime()
 
//convert dataset field “Timestamp” from UTC to local time
CDate(Fields!Timestamp.Value).ToLocalTime()

Units in format strings

There are 2 ways to add units to an output element (like a textbox or a table cell):

  • The first way is to convert the number to a string and then append the unit. This is done in the value definition of the output element. This way is not recommended, as the value is converted to a string and additional calculations in exported reports (e.g. export to Excel) will not be possible.
  • The ideal way is to use the plain numeric value as value for the output element and then apply the numeric format including the unit in the element format definition (property “Format”). But there are some things to consider when going this way that are explained below.

Firstly, the unit and the number information have to be concatenated into one string:

//3 decimals and hardcoded unit “kWh”
=”0.000 kWh”
 
//3 decimals and unit from dataset field “Unit”
=”0.000 “ + Fields!Unit.Value

This works fine for many reports, but not when the unit contains special format characters like the dot character or the zero character. Also, the Excel report export rendering engine might have problems with some units applied this way. So what can be done to avoid the problems that could arise? The first thought of most developers is, in that case, the problematic characters need to be escaped. This approach works well for many rendering engines, but not for the Excel rendering engine. The correct way is to declare the unit as a literal string. This can be done by adding quotes before and after the unit. As the quote character itself delimits the string, these characters need to be escaped by additional preceeding quote characters. So the strictly correct way to apply units to numeric output elements in the “Format” property is:

//3 decimals and hardcoded unti “kWh”
=”0.000 “”kWh”””
 
//3 decimals and unit from dataset field “Unit”
=”0.000 “”” + Fields!Unit.Value + “”””

Limitations of dynamic property values

In the development of zenon Analyzer and Report Viewer, we discovered that some of the background gradient types do not work correctly when they are set as a dynamic value (e.g. via report code functions). The background gradient types that are affected are “Horizontal center” and “Diagonal right”. When the value is set via the dropdown for the property in Report Builder, all values work correctly.

Tags: ,

Leave a Reply