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.
Related
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.
I am building a report(report server project) using the Data Tools. I have a column Quantity it has a Total.
I need another column that calculate the share(%) of each line in the Quantity comparing to the Total.
The expression would be: Line_1_Share = Quantity_of_line_1/Total.
I tried =[Sum(Total/Quantity)] but it does not even accept as a valid expression.
If you right-click the textboxes that contain your working 'Quantity' and 'Total' values and look at the expressions you will see the correct format.
For exmaple your 'Quantity' expression might be something like
=Fields!Quantity.Value
or if it is in a grouped row it might be
=SUM(Fields!Quantity.Value)
your 'Total' expression might also be
=SUM(Fields!Quantity.Value)
When you use SUM() (or any similar aggregate) then the scope of the expression decides what is included in the sum. The scope can be a single row, a row group or an entire dataset. If you do not specify a scope then the position of the textbox determines the scope.
So, if you have a simple table with no grouping other than the total line and your dataset name is dataset1 then your expression would need to be
=Fields!Quantity.Value / SUM(Fields!Quantity.Value, "dataset1")
The above reads .... "For the current row, take the Quantity and divide is but the sum of all Quantities that are within the entire dataset called dataset1"
If this does not help, post your current report design including and row and/or column groups.
I have a Matrix report that has two row groups and two column groups. There is column which has the calculation Max(Fields!AdjustedManning.Value) on the Row Group level as a subtotal. I want to add a total at the bottom which is outside of the row group to sum the subtotal numbers up. What expression can I use to do this? Effectively I'm looking to sum the max numbers
In the image the yellow box for design is where I need to put the expression and a preview of what I would expect it to calculate.
Design and Preview
You didn't show the rowgroup names so I'm guessing you have a rowgroup grouped by [WoLine] called Woline. Assuming this is correct then you should be able to use something like...
=SUM(MAX(Fields!AdjustedManning.Value, "WoLine"))
"WoLine" is the name of the rowgroup, you must include the quotes and it is case sensitive so adjust to suit your actual report.
What this does is get the MAX value within the "WoLine" rowgroup scope and then sum the results.
I have a SSRS report, and I'm trying to sum one of the columns.
The first column is a countdistinct(field1) and works perfectly.
The second column is in the same group as the first. When the first expands, the second column is part of the first group.
I'm trying to get the value here 24 in the group total.
if I perform a [SUM(CDEC(FIELD2.value))] it results in 72 because technically the 12 is repeated through all six records.
[SUM(MAX(FIELD2.value))] results in a 12, because the MAX() function gives max value of ALL the records.
How do I get 24, here?
Thanks
UPDATE #1.
here's the field setup for those columns
Someone mentioned using a scope in my sum(). How do I determine what my scope is? Thanks!
You have to add the scope in the sum expression in your tablix otherwise it always takes the dataset data. Let´s say you have a dataset (Dataset1), with the fields SalesOrder, SalesPrice. If you group now in your tablix by SalesOrder (GroupingBySalesOrder) you can add different scopes for the aggregate functions:
=Sum(Fields!SalesPrice.Value) 'This takes the Default scope "Dataset1"
=Sum(Fields!SalesPrice.Value, "Dataset1") 'The same result like above
=Sum(Fields!SalesPrice.Value, "GroupingBySalesOrder") 'The scope is now your grouping. Different result like the other two
My application uses SSRS to produce payslips for employees. The Payslip report consists of a tablix with 5 columns. Among the 5, is a column called "Units" and another called "Invoice value".
The report has several Row Grouping levels, but the only important one for this question is the Payslip Number Row Grouping "RG_SlipNum". There is a page break after each "RG_SlipNum" RowGroup.
When users want to print Payslips, they can optionally supply up to 5 parameters which filter the result set to print out.
Employees can be paid based on the number of units delivered * a rate (Unit Based), or by a percentage of the invoice value (Invoice based) for the delivery (Oversimplified, but hopefully, you get my drift).
If the employee is Unit based I want the Units Column to Show, and the "Invoice Value" Column to be hidden. If they are Invoice based I want both columns to show.
My dataset has a bit field indicating whether to show or hide a column based on the logic above. It will be a 1 or a 0 for every underlying row within the current rowGroup. I have tried to use the First(,) function in a Column Visibility expression on the "Invoice Value" Column. However, I get the following error whenever I try to limit the scope of the First Function to the current Payslip Rowgroup using the RowGroup name.
"The Hidden expression for the tablix 'X' has a scope parameter that is not valid for an aggregate function. The scope parameter must be set to a string constant that is equal to either the name of a containing group, the name of a containing data region, or the name of a dataset. "
So, my Question(s)
Can you define a RowGroup name as the Scope argument in a First() function?
If not, What's the best way of achieving this without completely re-working my Dataset / RDL to accomplish this. (Using SSRS2008)
Why is it always just after posting a forum question, you figure it (or some workaround) out?
I'd still like some (better) answers if anyone sees this, but I've set a cell in the tablix to the value of the bit field that determines whether to show the column or not. I then changed my Column Visibility expression to check the cell value (using ReportItems!textboxname.Value) and it's working. as I scroll the payslips the columns visibility changes appropriately.