Display a hierarchy with Reporting Services

7 04 2009

The reporting services limits can be easily reached when your customer ask you, for example, to display a department structure or an object composition.

In my example, we have:
Dep1
Dep11
Dep12
Dep13
Dep2
Dep21
Dep211
Dep2111

Structured in database like that:

rslevelsample

With Reporting Services, we know how to display a table and group elements.
A hierarchy can be built by 2 tips/settings:

First, we need to create a group row in the table. Then affect the expression with the main field(DepartmentId) and in the parent group section, indicate the parent of the current item(ParentDepartmentId).

With this first configuration, all the items will be displayed in the table through recursion like that:
Dep1
Dep11
Dep12
Dep13
Dep2
Dep21
Dep211
Dep2111

The second tip is the use of the level() function. The level function returns the hierarchy level of an item.
Thus, we can simulate a treeview representation with the repetition of a specific character.
In the first column of the table where the departement name is set, we can specify an expression:
=space(level())+ Fields!DepartmentName.Value
If we prefere others characters, =Replace(space(level()),” “,” *”)+ Fields!DepartmentName.Value

A good workaround to keep in mind !

Advertisements

Actions

Information

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: