I have a question about the avg-function in SSRS/Report Builder. What I want to achieve is a expression which is giving a average of the lead time per incident which is taking the urgency of the incident in account. I already made this simple expression for all the incidents which works fine: =Avg(Fields!Lead_time_call__in_days_.Value, "DataSet1")
This is the expression I made which should take the urgency in account (but which doesn't work): =AVG(IIF(Fields!Urgency.Value = "Low", Fields!Lead_time_call__in_days_.Value, 0), "DataSet1")
This displays this: screenshot
But that's not possible, since the individual averages can't be all lower than the total average (which is correct)
Does anybody know what I'm doing wrong? Thanks!
I fixed it! Thanks to #xcvd for helping. I just had to replace the 0 with nothing. That acts as a NULL and doesn't messes up the calculation.
Related
I have a report with two datasets to summarise the number and value of incomplete orders by status. I have a "Back Order" column, which is using the 'Lookup' function to refer to a second database, based on a whether the Fields!IsBackorder.Value returns true. This works at line level, but I've run into issues at the aggregate level.
For the total count of orders, this forumula works:
=SUM(IIF(LOOKUP(Fields!SalesOrderID.Value, Fields!SalesOrderID.Value, Fields!IsBackorder.Value, "DstBackorders") = "TRUE",1,0))
However, for the total value of orders ("Fields!NetValue.Value"), this returns '#Error'
=SUM(IIF(LOOKUP(Fields!SalesOrderID.Value, Fields!SalesOrderID.Value, Fields!IsBackorder.Value, "DstBackorders") = "TRUE",Fields!NetValue.Value,0))
I've tried custom aggregate functions but I haven't found any that work. I'm not sure how I'm getting this error.
Any suggestions would be really helpful.
Thanks,
Report Screenshot
The syntax looks perfectly fine , also the lookup looks good , can you please check on the below things in your DataSet:
Is Fields!NetValue.Value in scope of the current DataSet.
Are we using the correct data type for Fields!NetValue.Value(Something which is aggregatable , like int , decimal etc.)
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
I have been working on this for days without being able to solve yet. It's probably simple if you know what you're doing. I'm simply trying to make a standalone formula that is not in a tablix or anything, it's just in a textbox.
Here is an example of my Dataset called Dataset1:
What I am trying to get is a sum of the Actual Cost when the Category is Labor from Dataset1. My current expression is:
=Sum(iif(Fields!Category.Value="Labor", Fields!ActualCost.Value, 0), "Dataset1")
I refer to Dataset1 as my scope because otherwise, I get an error about using an aggregate expression without a scope.
The report runs but shows #Error in the textbox that has my expression in it. When I replace Fields!ActualCost.Value with a 1, I get the answer, 5, which is the correct number of rows with Labor as the Category. But it won't let me sum the numbers in the ActualCost column where Category is Labor.
Any ideas as to what I'm doing wrong? I feel like it's something to do with aggregating, but I'm not sure. Thanks!
It may have to do with the datatype of fields!ActualCost.Value. If that field is a decimal (regardless of how you have it formatted), try using cdec(0) instead of just 0 in your expression.
I have a column which should calculate some numbers and sometimes it gives me the correct sum and sometimes it doesn't. I don't know why! Can someone please point me in the right direction?
I used this expression:
=Sum(Fields!TotalEmployees.Value)
When I don't choose something from filters on the top , it will give me the correct sum:
And when I choose something from the filters on the top, for example between 2 dates, it will give me wrong the sum:
Parameters & Body of report :
#EndDateFrom
#EndDateTo
Yeah, you need to be wary of your grouping. I'm willing to bet you're stuck inside of a group which is filtering your results.
If you are using Report Builder 2016, you can right click your last row and select "Add Total". This will generally automatically generate a row that gets the sum of all fields in your group.
i solved this issue with changing my query ,where all calculating (AVG , Sum &.. ) happens in query , instead reporting services do it for me .. after that i got the correct number:
SELECT t1.Departments, count(t1.id), avg(t1.age),sum(t1.TotalEmployees)/count(t1.id)
AS TotalEmpl FROM (<current_query>) AS t1 <br> GROUP BY t1.Departments
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.