How to keep a conditional Running Value MS Reporting Services - reporting-services

I am trying to use Reporting Services to create a report displaying the call activity of various sales reps. The report will group by extension and then date of call. For each group of call dates (that is, all the calls for a particular date), I want to display some totals. One of the totals I want to display is the total number of calls whose duration greater than 2 minutes. I can see how to use the RunningValue function to keep a running total of ALL calls for the date, but I'm not sure how to make that conditional on the length of call. Any ideas?
UPDATE: The checked answer below did it... I used a case statement in linq like this:
var qry = from Q in c.CallList
select new
{
Q.Extension,
Q.CallDate,
Q.Duration
CallCountOverTwoMinutes = Q.duration > 120 ? 1 : 0,
};
Then I sum the value of CallCountOverTwoMinutes. Thanks for the help, Chris!

The easiest way would be to pass the value as part of the dataset. For example, using SQL:
SELECT Extension, CallDate, Duration,
CASE WHEN Duration > 2 THEN 1 END AS CallsOver2Mins
FROM CallTable
Then just sum on CallsOver2Mins.

Related

Report builder 3.0 count with where clause

For one of our reports I'm trying to get a count of rows that have the column Canceled with value 1. In the past I used the solution I found on Stackoverflow to use the Sum function with IIF, i.e.
=Sum(iif(Fields!Canceled.Value="True", 1, 0))
But now my source data has multiple rows for one booking_id so I need to add a distinct on that column. In SQL I could easily do
SELECT COUNT(DISTINCT(booking_id)) FROM Booking WHERE Canceled=1
But I can't figure out how to get the same behaviour in Report Builder 3.0. Any ideas?
Doing this in T-SQL, if possible, as suggested in the comments is not a bad idea, but you can do this in the report with an expression like:
=CountDistinct(IIf(Fields!Canceled.Value = 1, Fields!booking_id.Value, Nothing))
CountDistinct will ignore Nothing (i.e. Null) records, so you can apply a CountDistinct to an IIf expression that returns booking_id or Nothing based on Canceled.

SSRS Expression with parameter in WHERE clause

In SSRS, I'm trying to calculate the average number of months a client used a program. The programID is the parameter for the whole report. I'm trying to achieve this (not written with real syntax):
=Avg(Fields!length_of_stay.Value, 0))/30.0 WHERE programid = #ProgramID
Using this question, I came up the the following code which is producing an incorrect answer. I tested in SSMS to get the actual values to compare to SSRS results.
=Avg(IIF(Fields!programid.Value = Parameters!ProgramID.Value, Fields!Length_of_Stay.Value, 0))/30.0
The "/30" is used since the value is in days and I need months. I think the issue is using the parameter value chosen; this is my first report trying to calculate expressions with parameters.
Avg returns the average of all non-null numeric values. 0 is not null so it gets included in the average, distorting your result for every row with a different PragramId. Try using Nothing instead:
=Avg(IIF(Fields!programid.Value = Parameters!ProgramID.Value, Fields!Length_of_Stay.Value, Nothing))/30.0

SSRS how to get a running total of inventory amounts IN and OUT from START DATE to END DATE?

i have a stored proc returning inventory amounts between a start and end date.
the QTY field shows on-hand inventory adjustments by date, either IN or OUT.
i have a "run balance" field that needs to show the total QTY each day. if the InOut field is 0, it's QTY in. if it's a 1, its QTY out. the values reflected in In and Out are coded that way.
EXAMPLE. if i start on 4/1/14 with 5216. then 1061 of product is made on 4/1/14 i need the run balance to take 5216 and add 1061 on the next line. the next line should read 6277 instead of 1061. then if some is shipped, take 6277 and subtract, and so on.
i tried the running value on QTY, but it just repeats the QTY. doesn't calculate anything.
=RunningValue(Fields!QTY.Value,Sum,"Details")
i tried to post an image of my report preview, but i don't have the reputation ;-)
any help would be MUCH appreciated.
EDIT: OK, i tried this code block:
= Switch(RunningValue(Iif(Fields!InOut.Value = 0, Fields!QTY.Value,0),Sum,"Details"),
RunningValue(Iif(Fields!InOut.Value = "1", Fields!RunBalance.Value - Fields!QTY.Value,0),Sum,"Details"))
and i am getting a 0 on the sum fields, and #Error on the subtraction fields. but, i think this is more the direction i need to go (i hope)....but i am still not getting it.
There are a couple of things to look at here.
First, you specify the Scope of "Details" in your RunningValue expression... By default this group will have no grouping value, i.e. each row in the dataset will be in its own group. Which means the RunningValue will only ever be applied to one row only. Change the Scope to "MyDataset" or Nothing, whatever is appropriate.
Secondly, you need to consider how the InOut field affects the RunningValue.
I have created a simple Dataset:
And a simple table:
The Balance expression is:
=RunningValue(IIf(Fields!InOut.Value = 0, Fields!QTY.Value, Fields!QTY.Value * -1)
, Sum
, Nothing)
You can see this changes the Scope from your original statement, and also applies a multiplier to QTY based on InOut.
Works OK for my sample data:

Sum function in Report Builder 3.0

I am creating a report that will sum up all subtotal per MaterialNo/Color/Quality/Size.
Here's my sample report:
Computation will be GrandTotal = sum(Subtotal)
I am using =Sum(Fields!TOTAL_CTN.Value) but the result is 12.
Is there a way to compute using like =sum(subtotal_TextBoxName)?
I'm still not 100% sure of your underlying data and business logic, but here's one approach that might help.
I'm working off the following sample data:
Based on what your description above, it sounds like you have something similar to:
Which gives results:
It seems that you don't actually want to Sum TOTAL_CTN, rather this should be the same for every MaterialNo with the Sum only applied in the Grand Total.
As such you can change the Sub Total aggregation to Max and, since you're using Report Builder 3.0, you can then take the Sum of the group level aggregation values. The report will look like this:
Where the Grand Total expression is:
=Sum(Max(Fields!TOTAL_CTN.Value, "MaterialNoMax"))
In this expression MaterialNoMax refers to the name of the Row Group (based on MaterialNo in my example).
This gives your desired results:
The key here is thinking about what aggregation gets applied at each level and how these roll up to the end total.

MS-Access Calculating Percentage of Completed Tasks in a Report

As the title says, I'm looking for a way to calculate the percentage of completed tasks a person has. Data is structured so that each individual has can have many tasks, and each task can have many sub-tasks, as described below:
Employees
(pk)(AutoNumber)employee_id
(Text)FirstName
(Text)LastName
Tasks
(pk)(AutoNumber)task_id
(fk)(Number)employee_id
(Memo)Description
(Yes/No)Completed
Sub-Tasks
(pk)(AutoNumber)subtask_id
(fk)(Number)task_id
(Memo)Description
(Yes/No)Completed
I've been trying to make a report (named "Task Completion Rates") that lists all employees, the number of completed tasks they have, the total number of tasks they have, and their completion rate as a percentage. At the moment, I have the following two queries:
SELECT Count(employee_id) FROM [Tasks] AS TotalTasks WHERE [Tasks].employee_id =
Reports![Task Completion Rates]!txt_employeeID
SELECT Count(employee_id) FROM [Tasks] AS CompletedTasks WHERE [Tasks].employee_id = Reports![Task Completion Rates]!txt_employeeID AND [Tasks].Completed = 1
Are both of those necessary, or is there a way to get both counts from one query? Also, how would I go about using those totals in the report? The report's Record Source is set to the Employees table so that it can list them all. I've got text boxes ready to go for each total, but I'm having problems using the expression builder in the source for each text box to actually display the results of the queries. I set the source for one of the text boxes to =[qry_TotalTasksPerEmployee]![TotalTasks] (via expression builder) but it keeps prompting me to enter a value for [qry_TotalTasksPerEmployee]. Any ideas on how get this working?
Try taking the mean of your completed value. For example:
SELECT employee_id, -avg(Completed) FROM [Tasks] GROUP BY employee_id
The - before avg is because true is stored as -1, as pointed out by #Neil.
I'm not sure what you mean about the report - it should be easy to place query results in a report.
I'm not really into msaccess reports but since completed seems to be either a 0 or a 1 you should work towards the following query
-Edit turns out it's either 1 or -1 for bools so can't do a sum(completed) but need an IIF()
Select employee_id, count(*), sum(IIF(completed,1,0)), sum(IIF(completed,1,0))*100/count(*) as rate
From employees
Left join tasks
On tasks.employee_id = employees.employee_id
Group by employee_id
Note that this does create a division by zero problem for employees without tasks. You will have to deceide how to deal withbthose (exclude, show as 0% or ...)