THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Davide Mauri

A place for my thoughts and experiences on SQL Server, Business Intelligence and .NET

Custom Aggregations Values in SQL Reporting Services with Tablix Filters

In these last days I’ve been working on a BI solution for a logistic company. One report I have to create has a particular behavior that can make life a little complex if you’re using Reporting Services: the value used in rows and column totals is not calculated in any way, but is just taken from the database (SSAS in this case), just like any other cell value:

clip_image001

 

I’ve found this business case in a report that shows all the target values that a salesman has to reach. The total value for a month is not the average nor the sum of the target values for all the regions, but is just a fixed value set by someone (his manager, normally :-)) that represents that overall expected target for that month.

The data returned from the database (no matter if using MDX or SQL; in this example I’m using T-SQL but in reality I’m using MDX) look like the following:

clip_image001[8]

The null values in the region column represents the “total” value for that month, while for date (which is stored in a yyyymmdd integer format), as you may guess, the values for year are represented by the rows with value “0” in the month part.

If you just use these values in a Tablix, using the

clip_image001[10]

this is what you obtain:

clip_image001[12]

clearly the column “20090000” and the no-name row are in the wrong place, since they should be shown as the last and the rightmost values, just like what normally happens with totals.

How to do that? The anwser lies in the usage of Adjacent Groups and Group Filters.

The first step is to remove that row and column from the data. This can be done specifying a filter for the existing groups.

For the reference_data group you just have to say that you want to filter out all the data related to the 20090000 value:

clip_image001[14]

For the region, since we’re using a null value, we have to use a little trick since the operator “is” is not available.

In the Filter Expression field we have to specify something that will turn null to True or False:

=(Fields!region.Value Is Nothing)

then in the Value field you just have to specify “True” (or False if you’re using the “=” operator):

=False

Now, the matrix won’t display the “total” row and column. To show where we want we just have to add one Adjacted Group for columns and one for rows:

clip_image001[1]

So that at the end the matrix will look like this:

clip_image001[3]

 

Now, if you run the report, the result will be the one we expect:

clip_image001[5]

Published Friday, July 24, 2009 4:20 PM by Davide Mauri
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Elena said:

Hi Davide,

I have a similar set of data and my NULLs are labeled as "Total".

In  your example, is there a way to calculate the % from that Total for instance to understand performance of each Region/Period against the target?

Thank you

Lena

December 13, 2013 3:26 AM

Leave a Comment

(required) 
(required) 
Submit

About Davide Mauri

Davide Mauri - MCP, MCAD, MCDBA, MCT, MVP on SQL Server - has worked with SQL Server since version 6.5, and his interests cover the whole platform, from the Relational Engine to Analysis Services, from architecture definition to performance tuning. He also has a strong knowledge of XML, .NET and the Object Oriented Design principles, which allows him to have the correct vision and experience to handle development of complex business intelligence solutions. Having worked as a Microsoft Certified Teacher for many years, Davide is able to pass all his knowledge to his co-workers, allowing his team to deliver high-quality solutions. He currently works as a Mentor for SolidQ and can be found speaking in many Italian and internationals events.

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement