SSRS Group Footer - Expression to show a certain row from dataset - reporting-services

This is a report for Reps showing the customers sales for the previous day and the reps budget for the customer. So in my query I've already calculated the customer total, budget etc. which I managed to put into the report. The problem I have now is that the report's display is toggled so in the group footer I need to display the customer's total as well. I can not sum the column then it will include the budget. I need to input a expression, something like this:
=Tons WHERE ItemDesc = "Customer Total"
I have tried to google for a solution but all I can find is IIF statments. Is there anyway to do this?
Example:

You should be able to use something like this...
=SUM(IIF(Fields!ItemDesc.Value = "Customer Total", Fields!Tons.Value, 0))
All we are doing here is evaluating each row's ItemDesc, if it's "Customer Total" grab the Tons value if not grab 0... then sum all the results.

Thank you Alan Schofield but that did not work. After more searching I went with the lookup:
I added a second dataset with only the totals, then in the expresion for the footer I did the following:
= Lookup (Fields!Customer.Value,
Fields!Customer.Value,
Fields!Tons.Value,
"DataSet2")
This example helped me alot: http://www.sql-datatools.com/2015/07/lookup-functions-in-ssrs.html

Related

Trouble creating nested SUM IIF expression in SSRS

I am new to SSRS and have a SUM(IIF question.
My data set contains four columns: Date, GroupID, PlanPaid, and NetworkIndicator.
Here is an example of the data set:
I am trying to SUM the [PlanPaid] amount when [NetworkIndicator] = "In Network".
However, I need this amount broken up by the [Date]. I tried accomplishing this by creating the expression:
=Sum(IIf(Fields!NetworkIndicator.Value = "In Network"
, Fields!PlanPaid.Value
, Nothing)
, "Claims_Rolling12")
But this expression returns the same amount (total) across all [Dates]. How do I break it up so that it is grouped by the correct [Date]?
Here is a photo of my Tablix and my current Groups: [Tablix and Groups]
And here is a photo of the output: [Output]
You haven't said where you want this sum to appear, so the answer here might not work. If it doesn't then edit your question to show what you expect the output to look like based on your sample data.
I'm assuming here that you want to add a new column to the report that shows "In Network total" by date.
The easiest way to do this is to add a row group that groups by date, then within this group you can use a simple expression, like the one you tried, but without specifying the scope.
=SUM(IIF(Fields!NetworkIndicator.Value = "In Network", Fields!PaidPlan.Value, Nothing))
This expression will only sum rows that are within the current scope, in this case the scope will be the row group you created to group by dates.
As IO said, if this is not helpful, edit your question and show what you expect your end result to look like, based on the sample data you supplied and then I can look at it again.

SSRS Report SUM IF

Working on a ssrs report I ran into a problem.
In case that the Opening balance (the first row) is recorded as an Income, the Balance in the upper right corner
Should be reduced by the value shown in the "Income" cell for the Opening Balance row.
In case that the Opening Balance is recorded as Expenses the expression should stay as it is.
This is the expression for the Balance cell: =Sum(Fields!Income.Value-Fields!Expenses.Value)
Any help would be greatly appreciated :)
It looks to me like you need to take the balance, subtract the income and add the expenses from the row in your dataset that contains the description "opening balance...".
This could be achieved by using the initial balance calculation that you already have and doing a lookup to get the income/expense for the "opening balance..." line item based on the first 15 characters of the description ("Opening Balance"):
=Sum(Fields!Income.Value-Fields!Expenses.Value) - Lookup("Opening Balance", Left(Fields!Description.Value, 15), Fields!Income.Value, "DatasetName") + Lookup("Opening Balance", Left(Fields!Description.Value, 15), Fields!Expenses.Value, "DatasetName")
I'm guessing that this won't work out of the box and that you may have to test for nothing or COALESCE your database values and/or cast your fields to get this to work. Impossible to say exactly without seeing your actual dataset.

Is there a way I can get the Difference instead of the SUM on this report column

I'm not sure if this is enough info, but how would I enter the expression here to calculate the difference in income vs expense and then a total of those amounts:?
What I would like is something like:
balance = SUM(amount) when IncomeExpense = "Income" - SUM(amount) when IncomeExpnese = "Expense
balanceTotal = SUM(balance)
Every time I try to enter an expression into those fields, I get #Error on my report. I'm not sure what I'm doing wrong, any advice would be great, I'm obviously very new to "Expression" writing. If more info is necessary, I can get it. Thanks I appreciate any help!
Update: This is the Report being viewed, I've circled the values I want to find the difference:
something like this?
=Sum(Fields!Amount.Value * Iif(Fields!IncomeExpense.Value = "Income", 1.0, -1.0))
or if you don't like to multiply the values
=Sum(Iif(Fields!IncomeExpense.Value = "Income", Fields!Amount.Value, -Fields!Amount.Value))
The function for total should be the same. I presume you only have Income and Expense as values. If you want to explicitly check for Expense you can replace the Iif with a Switch statement like Switch(Income, +amount, Expense, -amount) in pseudocode.
EDIT: about expression editing: I find the easiest way to enter these expressions is in the expression builder/editor. Right-click on a box and you should be able to select "Expression" with a f(x) like icon.
The [Sum(Amount)] is another way of entering an expression but for calculations like this you will need to edit expressions most of the time. In the background, [Sum(Amount)] is also an expression: =Sum(Fields!Amount.Value). Try it out by editing the expression one of your existing totals.

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.

SSRS 2008 R2 Chart - Display Chart average and Group average

I have the following requirement for a report.
I have a repeating bar chart within a Tablix region (grouped by individal). On that chart, I need to display the percentage of a value (call it sales) for each month. So a chart will have a single employee, with a bar for each month, showing the month total sales as a percentage of the grand total sales. That's the easy part: my expression shows (=Sum(Fields!Sales.Value) / Sum(Fields!Sales.Value, "EmployeeChart").
My next requirement is what has me stumped. I need to display the average Sales Percentage value for each employee as a line (or bar) next to the individual Sales Percentage value. So for each month, I need to know how the Percentage distribution compares to the group average Percentage.
The end result has one graph repeated for each employee, with a bar series showing the percentage of sales in each month, and a line series (which has the same values in each chart) showing the average sales percentage of that month for all employees.
I've tried the following, and haven't gotten the results I want.
=Avg(Sum(Fields!Sales.Value) / Sum(Fields!Sales.Value, "EmployeeChart"), "EmployeeTablix")
I've also tried various combinations of declaring scopes, none of which worked - I can't get it to give me the average of multiple group separations (e.g., SalesMonth and EmployeeTablix) .
Any suggestions?
Why don't you divide the grand total by total number of months in your chart for a line chart type?
=Sum(Fields!Sales.Value, "EmployeeChart") / CountDistinct(Fields!Month.Value)
... or similar for your dataset.
Shew this one is a bit old but I came across it when looking for solution to a related problem I am having with averages shown on a chart. I thought I can share what I have done as it might be a solution?
I am working on something similar in SSRS. I have a chart giving total volumes per day of three items for a week.
On the label of each day I have added (Appended) a total of all items on that day. And under the series (Showing the colours for each item) I have added an average for the week for each item.
Here's an example..
(My averages are a bit off with only the last average being correct.)
To append this information to the labels of category or series groups in SSRS you need to do the following:
Click on the series group you want to edit of the chart. This will display a little "Chart Data" window listing "Values," "Category Groups" and "Series Groups".
Right-click on the item under either Category or Series group that you want to work with and click on "Properties".
Click on the fx button next to the "Label" field to open the Expression editor.
Add the information you want to display separated by "&". For example: =Fields!Day.Value & "(Tot.: " & SUM(Fields!Matters.Value) & ")"
This example will display the Name of the day with the text " (Tot.: ", the totals for all items on that day and ended off with ")". As in "Mon (Tot.: 486)".
If you want to list the appended information below the label, then you must add vbcrlf between some &'s.