SSRS subtotalling columns with expressions - reporting-services

Using Visual Studio 2010 and SQL Server 2012
I have made an SSRS report that requires a custom method to subtotal and arrive at a grand total for Percent of Assets and other calculations derived from Percent of Assets. I cannot simply use the Add Total Function because it is grayed out as is typical when summing expressions. I cannot manually calculate the subtotals because I get a nested aggregate error.
The software I'm using to make this SSRS report provides various stored procedures and functions to make reports using derived computations. The stored procedure contain a Percent of Assets column but because the report is filtered to show only common stock, the percentage of Assets function is incorrectly still counting unfiltered assets in its calculation. The assets under consideration make up 59.7 % of total holdings but I need the report to behave as if they were 100% of holdings.
To understand some of the math in this report please look at the following report output. Note that the report I want only includes common stock which make up 59.7 Percent of total assets as mentioned.
This report represents the desired output which is currently being calculated in a different reporting program. The report has two tables
% Company Sales is a hard coded value that represents the percent of sales that are either domestic or international. You see this and % Portfolio Assets in both the international and domestic tables.
% Portfolio Assets is calculated by multiplying the percent of assets of a given holding by the hard coded company sales value. In the first example McDonald's 2.1% Portfolio Assets is 6.6% * 32%.
6.6% is the percent of Assets McDonald's represents in the portfolio is if you only count common stock (exclude cash)
McDonald's Value Total Portfolio Value %
4,950.00 / 73,919.50 = 6.6000%
Domestic/ International Percentage breakdown
Total % Sales %Split Region
6.60% 32% 2.1% Domestic
6.60% 68% 4.5% International
Now here is my report output. It differs slightly from the design layout I will be showing because I added columns and changed the headers for explanatory purposes in this preview example. So far I am just trying to get the Domestic table to work. Once that is working I will build the international table. I have a few extra colums that I'm using for troubleshooting.
I have tried several methods to Calculate Portfolio Assets. I can get the individual row values to be correct but I cannot get the subtotal value to be correct using different methods due to a nested aggregate error (summing and already summed expression when a data scope is used) The grand total is also important but for now I'm just trying to get subtotal working.
Here is one method to get the row detail value for Percent of Assets. This is used in the calculated Percent Column. This column is the one that won't allow me to subtotal without a nested aggregate error.
When I try to use the following expression to get the subtotal I get the nested aggregate error
=SUM(Fields!MarketValue.Value/Sum(Fields!MarketValue.Value, "DataSet1"))
ERROR Error 2 [rsInvalidNestedDataSetAggregate] The Value expression for the text box ‘Textbox39’ has a nested aggregate that specifies a dataset scope. Inner aggregates cannot specify a dataset scope.
If use the PercentAssets field which is included in the Stored Procedure I can subtotal and get grand total without errors but the value is the filtered value which only sums to 59.7 if I multiply this filtered percent by the company sales the value is wrong.
Last I tried to use custom VBA code to get my subtotal and grand totals. However this provides a running total of the calculated percents not the subtotals I need for the SectorName groups.
Here is the VBA Code I used which I found on the web here:
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/1d3c5ec1-89cb-4108-8637-ff434027b1ec/sum-an-expression-value-ssrs
Dim public nettotal as Double
Public Function Getvalue (ByVal subtotal AS Double) AS Double
nettotal = nettotal+ subtotal
return subtotal
End Function
Public Function Totalvalue()
return nettotal
End Function
Code deployed
In summary I need to multiply the calculated Percent column's values by the Company sales. I need to subtotal the result of these calculations.
If you look in the Information Technology Sector Grouping you can see the original report correctly arrives at 32.8 as the subtotal.
My report incorrectly arrives at 100% because that is the running total tally of the Calculated percents.
Here is a link to the original rdl
https://dl.dropboxusercontent.com/u/87501202/InternationalDomestic.rdl

It looks like your code:
=SUM(Fields!MarketValue.Value/Sum(Fields!MarketValue.Value, "DataSet1"))
isn't quite correct... Try this instead:
=SUM(Fields!MarketValue.Value)/Sum(Fields!MarketValue.Value, "DataSet1")
Breaking it down slightly, the second piece of code is expression / expression; now it's just two SUM expressions with different scopes as required - the first one looks like the syntax is off slightly, hence your error.

Related

I'm trying to aggregate a measure in Power BI Report Builder and getting nowhere

I am working on a sample project in Power BI Report Builder. (I couldn't tag it as such because apparently I'm not allowed to create my own tags on this website.) The measure I am going for in my data cube is called Direct_Claim_Deductible_Recoverable_End_of_Year, but we will call it "Deductible" because that's too long a name to type out every time. I am trying to divide it up by the fields of State, City, and Year.
The Category column tells you whether each row is for a state or a city within that state. The Year and Location columns tell you the year and location that the row is telling you about. The Deductible column shows that measure. The Pct% column formula is Deductible - Total. (I added the Total column because I was having trouble with the Pct% column and wanted to know what was going on.)
Here's where the problem begins.
The Total column is supposed to tell me what the total deductible is for that specific year. But instead, it just gives me the grand total for all years in the cube. I've run the report enough times to know that this number is $99,669.71.
Here is the formula I am using for the Total column:
=round(Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value),2)
The Pct% column is giving me wrong answers too, but it is based on the Total column, so fixing the Total column should also fix the Pct% column.
And the data bar is supposed to show me what percent of the total for that year is in that state's row, or what percent of the total for that state is in that city's row. Instead it gives me an error message saying I am missing a closing parenthesis ')' somewhere:
The Maximum expression for the chart 'DataBar2' contains an error: [BC30198] ')' expected.
Here is the code I used:
=(Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value) / (Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value), "StateDS"))
As you can see, all three sets of parentheses are opened and closed.
I did figure out that if I move all the parentheses to the end, like so:
=(Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value) / (Sum(Fields!Direct_Claim_Deductible_Recoverable_End_Of_Year.Value, "StateDS")))
I resolve that error message but get a different one:
The ValueAxis_Primary.Maximum expression for the chart 'DataBar2' has a nested aggregate that specifies a dataset scope. Inner aggregates cannot specify a dataset scope.
It seems to be telling me that I cannot have the denominator of the fraction for the City data bar specify that its scope is the dataset "StateDS", which is the dataset that aggregates by State alone. But I am confused. I don't understand why that would be. And I don't understand what I need to do to make it aggregate by state anyway.
Thank you.

SSRS - add percentage of total?

I am just starting out in SSRS and have a dataset that looks like the below.
I have built this in a matrix table like so
I want to show what percentage each of the rows total is of the grand total, so for the attached image I would want to show what percentage 35 (counselling calls) is of 47 (total) and what percentage Legal calls (12) is of total (47)
I have tried =Fields!Calls.Value/sum(Fields!Calls.Value) but that just gives me 100% for both?
Would appreciate any help
You need to specify the scope of your SUM() expressions.
I'll briefly explain how scopes work and then get to the answer.
SSRS always evaluates an expression based on it's scope which is usually defined by the physical location of the expression within table/matrix. As you can see from your design all 4 textboxes show the same expression, [SUM(Calls}] which in fact is actually =SUM(Fields!Calls.Value). However they give different results because the scope of each is different. The first is in the category rowgroup and the month column group for example, the second one is in the category row group but in the total month group, and so on...
OK, now to the answer !
Assumming
your rowgroup is called 'CategoryGroup` (you will see the name in the rowgroup panel under the main designer)
your dataset is called DataSet1
You expression should be
=SUM(Fields!Calls.Value, "CategoryGroup") / SUM(Fields!Calls.Value, "DataSet1")
This basically reads..
Take the sum of the call column for all rows that are within the current CategoryRowgroup and divide by the sum of the call column across the whole dataset.
Notes
The scope names must be enclosed in quote and are case sensitive
The scope names must match either a row or column group, or a dataset name exactly.
the , "CategoryGroup" scope argument can probably be omitted as this should be the scope of the textbox anyway.

query of calculate the annual profit growth in qlikview by using text object

I want to calculate the annual average profit growth rate for 5 years by using a text object. Qlikview does not seem to support nested aggregation... I am new to QlikView, can anyone can help me?
Tried query:
='Annual Growth Rate (2003-2007) :' & avg((sum(Profit_per_Product)/sum(Total_Retail_Price))*100)
Thanks in advance!
QlikView does support nested aggregation and can fulfil your requirements if you utilise the AGGR function. This function allows you to perform aggregation over a set of dimensions that you specify and in its simplest form, can be use as follows:
=aggr(expression,dimension)
This means that expression is evaluated for each value of dimension. For example, in your case if you used sum(Profit_per_Product)/sum(Total_Retail_Price) as your expression, and used your dimension that contained your data's year, then aggr would result in five different values (one for each change in your year). As you wish to take the average, then the AVG function happily takes these five values and provides you with your desired result.
Therefore, all you need to do is to slightly change your expression to the following (here I assumed that your dimension that contains the year is named Year):
='Annual Growth Rate (2003-2007):' & num(avg(aggr(sum(Profit_per_Product)/sum(Total_Retail_Price),Year)),'0.00%')
I also added the NUM function to format your result as a percentage.
More information on Advanced Aggregation (i.e. AGGR) may be found in section 25.2 of the QlikView Reference Manual (in my copy it's on page 291).

How can I add an aggregate percentage to an SSRS report based on two specific columns in a matrix?

I am somewhat new to SSRS and I have built a matrix report that looks fairly simple:
Supplier [AccDate]
[SupplierName] Sum(PurchasingCredit)
Total <<Expr>>
The actual report shows month-by-month sales data for a year in addition to Current YTD and Previous YTD columns (joined via UNION clause in base query) in addition to a column showing Year-over-Year % as difference between the Current YTD and Previous YTD columns (also joined via union).
I was able to apply a dynamic format to the Year-over-Year column using the following expression in the Format property to show the YOY column as a percentage and the others as dollar amounts:
=IIF(Fields!AccDate.Value <> "YOY", "'$' #,0.00;'$' -#,0.00", "#,0.00 %;-#,0.00 %")
The last thing I need to do is to show the column totals, which are working for each column with the exception of the year-over-year percentages using the following:
=IIF(Fields!AccDate.Value <> "YOY", SUM(Fields!PurchasingCredit.Value), 0)
In the year-over-year (YOY) column, a sum of percentages doesn't make sense: I need it to recalculate this value based on the sums of the "CYTD" and "PYTD" columns, but I can't seem to figure it out. Any help would be greatly appreciated. I am guessing it is probably an application of scope, but the MS articles that attempt to explain this are very confusing.

SQL Server 2008 R2: Calculated Member is SSAS not pulling correctly in SSRS

I have a calculated member in SSAS cube which gives a percentage. In the cube browser this aggregates correctly but in BIDS SSRS it adds all the grains together to give a meaningless result. I know I could average the results but this isn't acceptable as I need a weighted average, which is why I created the calculated member in the first place. Help! How do I get this to work?
Here's the detail:
The calculated member in SSAS looks like this:
ActiveTimeVsExpectedActiveTime = (AvailableTime + TimeOnPhone + TimeInAvailable)/ExpectedTimeOnPhone
This works perfectly in the cube browser; it calculates correctly for all the individual telephone agents, and this feeds through the hierarchical group correctly to give a weighted result i.e. instead of adding together the result of the calculated member for each individual and calling that the team total, it sums together all the elements of the calculation and puts the results through the calculated member equation.
In SSRS however it just adds together the results of the individual calculated members and calls that the Team result. Help! I've searched online for a solution but can't find one. It doesn't make sense...why does the cube browser automatically calculate it correctly without any problem if SSRS doesn't - it makes calculated members rather pointless doesn't it?!
OK, so in response to Diego's question, I am including some of the data to clarify a bit further... The issue replicates on lots of calculated members; this is from the report I am building at the moment. T
he calculated member is Adherence = Adhering Time / Rostered Time
This is what it looks like in SSRS reporting:
Adhering Time Rostered Time Adherence
Team1 275736 366600 908.58%
Agent1 29355 30000 97.85%
Agent2 22041 33000 66.79%
Agent3 27493 30000 91.64%
Agent4 26689 30000 88.96%
Agent5 0 30000 0.00%
Agent6 27447 30000 91.49%
Agent7 30000 30000 100.00%
Agent8 28725 30000 95.75%
Agent9 0 32400 0.00%
Agent10 30142 31200 96.61%
Agent11 27201 30000 90.67%
Agent12 26643 30000 88.81%
As cou can see at the top of the data, it calculates the team adherence as being 908.58%, which is the sum of the adherence results of every agent.
SSAS cube browser shows exactly the same results for each agent but gives the team total as 75.21%, which it calcualtes as coming from 275736 adhering time and 366600 of rostered time.
Calculated Memberes are calculated at run time. Any chance the data changed between the interval you compared the cube and the SSRS. Also, are you sure the hierarchy you are using to compare is the same. The [Product].Name can be different if you are browsing the product attribute of a DimProduct dimension for example and the product on a hierarchy containing other members