SSRS: Need to get total numbers of calls which are less than 10 seconds - reporting-services

Looking to get total numbers of calls which are less than 10 second . i have tried these SSRS expression . but result is not accurate.
=SUM(IIF(DatePart( "s" ,Fields!call_dur.Value) <= 10, 1,0)
Please help me on this
Call_Dur
---------|
00:00:05
=SUM(IIF(DatePart( "s" ,Fields!call_dur.Value) <= 10, 1,0)

Related

how to calculate Average of hour and Minutes in SSRS report

How can i caluculate average HH:MM in SSRS Report.I am getting data with below query
select O.ORDERNUM, Cast(DateAdd(s, AVG(CAST(DateDiff( s, '00:00', cast(DROPTIME as time(0))) AS INT)), '00:00' ) as Time(0)) AS ATIME
FROM ORDE_ O
WHERE
O.CLIENTNUM='HLEX1'
Data is coming like below
OrderNum ATIME
123 16:20:30
124 17:30:00
125 17:56:43
126 17:55:00
Here i want to display Average Hour and Minutes
How can i do this thanks for your help.
I would change the approach slightly. Instead of getting each order's average time and returning a time datatype, just return an integer in seconds. You can then get an average of those integer values and convert back to a time form (if required) in the report itself.

SSRS report builder 2014 CDbl precision

I have some column in my report, calculated the Sum using this exepression :
=SUM(IIF(Fields!Type.Value = 0, CDbl(Fields!Amount.Value), CDbl(0.0)))
it works but gives me the sum with no precision.
is there a way I can view the Sum with precision?
UPDATE
the Fields!Amount.Value is alway decimal(18, 3)
If The calculation was like sum = 10 + 10 the result becomes 20
if sum = 10 + 2.125 the result becomes 12.125
I want the result to be converted to (18, 3).
so I expect the result in the first example to be 20.000
Your report is correctly returning the values to the necessary precision, it is just only showing the significant figures because you have not told it what number formatting you require and is making a best guess.
If you change your expression to the below, you should get your desired output:
=FORMAT(SUM(IIF(Fields!Type.Value = 0, CDbl(Fields!Amount.Value), CDbl(0.0))),"0.000")

Cast works on one field but not other

I have two fields in my table, Cycle and Idle, both are nvarchar(50) and both contain time. I am trying to get a total for each field based on a particular program number using TSQL. Below is a small example of the data.
Id ProgramNo Cycle Idle
209702 3998_BOTH_OPPS.MPF 00:02:41 00:00:25
209703 472_7580_OPP1.MPF 00:02:08 00:01:44
209704 3998_BOTH_OPPS.MPF 00:00:27 00:00:11
209705 3998_BOTH_OPPS.MPF 00:00:00 00:00:00
209706 3998_BOTH_OPPS.MPF 00:00:01 00:01:40
209707 9491_OPP1.MPF 00:00:00 00:00:00
209708 9491_OPP1.MPF 00:00:01 00:00:04
209709 9491_OPP1.MPF 00:01:05 00:00:19
So for example, get the total Cycle time and Idle time for ProgramNo 3998_BOTH_OPPS.MPF and 9491_OPP1.MPF
This is my query...
SELECT
ProgramNo,
cast(dateadd(MILLISECOND, sum(datediff(MILLISECOND, 0, cast(Cycle AS DATETIME))), 0) AS TIME) AS CycleTime,
cast(dateadd(MILLISECOND, sum(datediff(MILLISECOND, 0, cast(Idle AS DATETIME))), 0) AS TIME) AS IdleTime
FROM Cycle
GROUP BY ProgramNo
It works just fine for CycleTime but I get an error for IdleTime:
"Conversion failed when converting date and/or time from character string."
Any suggestions? Thank you in advance.
You need to find values that don't match the HH:MM:SS format.
Here is one simplistic method:
select idle_time
from cycle
where idle_time not like '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]'
If that doesn't work, then look at the components:
where (idle_time like '[0-9][0-9]:[0-9][0-9]:[0-9][0-9]' and
(not (left(idle_time, 2) between '00' and '23') or
not substring(idle_time, 4, 2) between '00' and '59') or
not right(idle_time, 2) between '00' and '59')
)
SQL Server 2012+ makes this much easier with try_convert().
Based on your comment above, you can fix your data like so:
cast(dateadd(MILLISECOND, sum(datediff(MILLISECOND, 0, cast(right(Idle,8) AS DATETIME))), 0) AS TIME) as IdleTime
We are just looking at the right most 8 characters... so if there isn't a #. before your time it will still work
select right('3.18:15:05',8)
select right('18:15:05',8)

Using DatePart() with date ranges crossing the datepart boundary

I am currently trying to summarise some data tables into a report. Each record in the table consists of a date range, something like this:
StartDate EndDate
--------------------
13/04/13 15/04/13
17/04/13 24/04/13
28/04/13 03/05/13
05/05/13 10/05/13
Assuming the date ranges signify something like days of leave, I want to be able to calculate the total amount of days of leave per month. I came across the DatePart function which seems to work apart from one edge case: when the date range crosses a month boundary. Since the DatePart function returns the month for one given date, I am no longer able to use that to determine the amount of days of leave for that edge case record (in the example above it is record 3), since it applies to two separate months.
Ideally I want my final table to look like:
Month #OfDays
--------------------
4 11 (1st record - 2, 2nd record - 7, 3rd record - 2)
5 8 (3rd record - 3, 4th record - 5)
I've considered some messy options, such as populating a temporary table having each record signifying a different day and then doing a query on that, but I am not sure how this ties in with a report. Right now my report record source is the (incorrect) query, is it possible to have a record source as a VBA function that returns a recordsource?
Another thing I thought was to possibly to have an initial query that splits up any edge cases into two seperate records, where the date range only covers one month, and then use that for my final grouping query. Is that even possible?
I feel there may be a much simpler solution to this problem yet I can't see it.
If anyone has any ideas it would be much appreciated!
To accomplish your task using Access queries you will need to create a table named [Numbers] with a single Number (Long Integer) column named [n] containing the numbers 1, 2, 3, ... up to the highest year you expect to be working with. I created mine as follows
n
----
1
2
3
...
2499
2500
You'll also need to paste the following VBA function into an Access Module
Public Function IsValidDayOfYear(YearValue As Long, DayValue As Long) As Boolean
Dim IsLeapYear As Boolean
If (YearValue Mod 400) = 0 Then
IsLeapYear = True
ElseIf (YearValue Mod 100) = 0 Then
IsLeapYear = False
ElseIf (YearValue Mod 4) = 0 Then
IsLeapYear = True
Else
IsLeapYear = False
End If
IsValidDayOfYear = (DayValue <= IIf(IsLeapYear, 366, 365))
End Function
Let's assume that your source table is called [DateRanges]. We'll start by creating a query that generates every day of the year for each year represented in the source table. The trick here is that DateSerial() "rolls over" month boundaries, so
DateSerial(2013, 1, 32) = #2013-02-01#
and
DateSerial(2013, 1, 234) = #2013-08-22#
SELECT DateSerial(yr.n, 1, dy.n) AS [Date]
FROM Numbers yr, Numbers dy
WHERE
(
yr.n
BETWEEN (SELECT MIN(DatePart("yyyy", DateRanges.StartDate)) FROM DateRanges)
AND (SELECT MAX(DatePart("yyyy", DateRanges.EndDate)) FROM DateRanges)
)
AND (dy.n < 367) AND IsValidDayOfYear(yr.n, dy.n)
For your sample data, that query returns all days in 2013.
Let's save that query as [AllDays]. Now we can use it to extract the individual days for each date range (omitting StartDate so the final counts match yours in the question)
SELECT [Date] FROM AllDays
WHERE EXISTS
(
SELECT * FROM DateRanges
WHERE AllDays.[Date] BETWEEN DateAdd("d", 1, DateRanges.StartDate) AND DateRanges.EndDate
)
That returns the individual days corresponding to each range, i.e.,
Date
----------
2013-04-14
2013-04-15
2013-04-18
2013-04-19
2013-04-20
2013-04-21
2013-04-22
2013-04-23
2013-04-24
2013-04-29
2013-04-30
2013-05-01
2013-05-02
2013-05-03
2013-05-06
2013-05-07
2013-05-08
2013-05-09
2013-05-10
We can save that query as [RangeDays] and then use it to calculate our counts by month...
SELECT DatePart("m", [Date]) AS [Month], COUNT(*) AS NumOfDays
FROM RangeDays
GROUP BY DatePart("m", [Date])
...returning
Month NumOfDays
----- ---------
4 11
5 8

MySQL MONTH returns wrong results

The following query didn't return correct results, because it returns results from "September" month but i need to get results from given month "August".
Is there something wrong in my query?
SELECT *
FROM table
WHERE YEAR(FROM_UNIXTIME(UNIX_date)) = '2012' AND
MONTH(FROM_UNIXTIME(UNIX_date)) = '08'
order by UNIX_date DESC
EDIT:
results that returned were like that:
post_id user_id UNIX_date
95319 12 1346475459
97370 5 1346474849
83527 25 1346474631
83526 51 1346473357
85929 12 1346471009
26677 29 1346462100
26839 12 1346432911
85927 12 1346411636
The month should not have a leading 0. So try 8 instead of 08.
You could also post a line of what is being returned so we can see how UNIX_date looks like.
reference: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_month
As written in the documentation http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_month, the DAY, MONTH and YEAR functions returns integer, thus values 1-12 (or zero) for the MONTH.