Solved

Reporting Services -- Aggregate Row and Col groups simultaneously.

Posted on 2009-04-06
9
3,478 Views
Last Modified: 2012-05-06
It seems like this should be easy.

I have a report that looks like this:

                                                           Col1   Col2   Col3
RowGroup1   RowSubGroup A           2         3       1
                       RowSubGroup B           4         2       1
                       RowSubGroup C           1         2       3
                       Total                               7         7       5

RowGroup2   RowSubGroup A           1         2       3
                       RowSubGroup B           4         7       1
                       RowSubGroup C           2         1       0
                       Total                               7         10     4
                       

I'm using the matrix control as the number of rows and columns can vary.  the numbers in th middle are actually summations of the raw data being returned by the query.

I want to turn the summations into percentages (of the subtotal on the row group).  I can't find a scope that works to get me the total that you see at the bottom of RowGroup1 or RowGroup2.

if I use sum(Field,"RowGroup") (naming the highest level row group, i get the sum including all of the columns.  If I use the column group name as the scope, I get the whole page of rows -- not just the specific row group that I'm looking for.

There has to be an easy way to do this, but I haven't figured it out yet.
0
Comment
Question by:bens4lsu
  • 3
9 Comments
 
LVL 8

Expert Comment

by:Hadush
ID: 24101709
If you select the whole matrix and Properties -->Groups you see the top group name (by default it gives matrix1_Groups) and use that for your expression as shown in the details field
=Sum(Fields!Col1.Value)/Sum(Fields!Col1.Value,"matrix1_Groups")  and change the format to P (for perncetage and if you need decimals like 10.00% then P2)
 
Remove the .xls extension and you can view the sample rdl file
Let me know if this helps
 

Copy-of-PercentagePerSubtatol.rd.xls
0
 
LVL 2

Author Comment

by:bens4lsu
ID: 24102317
Hadush,

That works in your example because your columns are static.  I'm building the columns dynamically based on the result set.  So in my example, the data would come back from the server like this...

RG1, RSBA, Col2
RG1, RSBA, Col3
RG2, RSBC, Col2
etc.

I don't have a single Group that is on top.  I have two Row Groups and one Column Group.  If I sum over the row group, I get the percentages across all columns, and if I sum over the column group, I get all of the row rather than just that short little group that I want.  If there were a way to sum over both....
0
 
LVL 26

Accepted Solution

by:
Chris Luttrell earned 500 total points
ID: 24174255
Ben,
How does the output in this sample output look?  It was done with a matrix so columns and rows are dynamic.  But I calculated the percents in the SQL statement shown below.  The RDL is attached.
SELECT OuterGroup,

	   SubGroup,

	   FactCol,

	   convert(float,Fact)/sum(Fact) over (Partition by OuterGroup, FactCol)  Fact

FROM QuickMatrix2 QM2;

Open in new window

AggregateRowAndColGroups.png
Report7.rdl.txt
0
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 24174646
You may have to do it in the query like I did.  I found MS site, http://msdn.microsoft.com/en-us/library/ms159673.aspx, that expliciltly says
Note:  
You cannot aggregate values across both a row group and a column group in a single expression. Writing an expression that includes an aggregate with a row group scope and another aggregate with a column group scope is not supported.  
I did not take their word and tried to "trick it" but I get "Aggregate functions cannot be nested inside other aggregate functions" from RS for my efforts.
0
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 24188847
bens4lsu,
Just curious, you only gave it a B, what was wrong with it?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query Missing Money orders... 6 70
SQL query 4 29
sql query to reportserver  table error 3 23
SQL Inner Join Vs SubQueries 9 25
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now