SSRS Group by Time Expression - reporting-services

I have data that for time bands I would like to add to my group properties expression on SSRS, the data is in the image
I would like to display this like the image below, with this grouping by time I set so 00:00 to 01:59 etc
I had this in my expression but this doesn't work
=IIF((Fields!HourBands.Value >= "00:00" and Fields!HourBands.Value <= "02:59") or (Fields!HourBands.Value >= "03:00" and Fields!HourBands.Value <= "04:59")

Related

SSRS 2008 parameter dates and nulls

I have a report of customers that I wish to run in SSRS. The report I want to return is for a particular period (e.g. 01/01/2016 and 29/02/2016). The parameter is against a date field (End_Date).
What I would like to return is a list of customers WHERE End_Date is either BETWEEN the dates above (or any other period) and WHERE End_Date IS NULL too.
I am able to create a parameter that will list customers with an End_Date between the dates I want but how do I also get the parameter to also list the NULL values.
Hopefully that's clear but just in case - I need a list of customers where End_Date is between two dates or NULL.
Thank you
You need to account for the possibility of a null in your evaluation using an OR for the END_DATE.
Are you using the parameter in the query or on the dataset? The SQL is a bit different that the SSRS expression.
SQL
WHERE DATE_FIELD >= #START_DATE AND (DATE_FIELD <= #END_DATE OR #END_DATE IS NULL)
SSRS
=IIF(Fields!DATE_FIELD.Value >= Parameters!START_DATE.Value AND (Fields!DATE_FIELD.Value <= Parameters!END_DATE.Value OR ISNOTHING(Parameters!END_DATE.Value), 1, 0)
In the other filter properties, set the type to Integer, Operator to =, and Value to 1.
This will evaluate the expression and return 1 if it matches and 0 if not - then it filters for the 1.

SSRS expression Year and Month only from Date field

How do I build an expression in SSRS that only captures the Month and Year and not the day from a datestamp field?
I am trying to create a Month To Date column in SSRS. I have a date timestamp field, I also created a Month field and a Year field in hopes of solving my own problem. I didn't.
I have an expression built that allows me to capture the month and it works, but in my data set I have July data for both 2013 and 2014. This expression I only want to capture 2014.
=Count(IIF(Fields!Date_Month.Value = Month(Today()), Fields!AcctNo.Value, Nothing),
"Eligibility")
and I got it to work for the Year:
=Count(IIF(Fields!Year.Value = Year(Today()), Fields!AcctNo.Value, Nothing),
"Eligibility")
Can I somehow combine the 2 expressions? Should I?
Orrrrrrrrrr
I have tried to use my datestamp field to no avial: I get #Error with this abomination
=Count(IIF(Fields!Datestamp.Value = Month(Today()), Fields!AcctNo.Value,
Nothing), "Eligibility")
I'd think the preferred way is to use my above datestamp field and parse out the month and year. It's the way I'd do it....if I knew how to actually do it.
As you've suggested, you can combine the two expressions you have to get your required result with a few small changes:
=Count(IIf(Year(Fields!Datestamp.Value) = Year(Today)
and Month(Fields!Datestamp.Value) = Month(Today)
, Fields!AcctNo.Value
, Nothing)
, "Eligibility")
This will count all rows in the Dataset that have the same year and month as the current date.

SQL query to select data between dates does not show last date

im using a query to get data between dates but for some reason it does not pull the data of the last date selected here is my query:
SELECT * FROM order WHERE status = "completed" AND orderdate >= ? AND orderdate <= ? ORDER BY orderid DESC
Im using is equal to or less then... but still?
what am i doing wrong ?
SELECT * FROM order WHERE status = "completed" AND date(orderdate) >= date(?) AND date(orderdate) <= date(?) ORDER BY orderid DESC
It happened with me also, but in my case instead of passing a date I was querying using a datetime variable, Please make sure you are querying with date variable only.
Make sure that orderdate is date as well as your query parameter is also date, or use appropriate function to convert them in date, than query.
Your dates are actually datetimes - so you are actually, in the case of the upperbound, saying "12 midnight" on whichever date you choose. Hence, if it tries to test a value at say 10am in the morning, it fails as being outside the range.
Either set the upperbound date one day forward, or explicitly only test the date part of the datetime...

SSRS Charts data

I have situation where I need to create a column chart.
I have a field NotificationLog.Duedate . With this due date I need to create a chart with various condition.
I need to calculate the count of rows with conditions like below
NotificationLog.Duedate < Present date
NotificationLog.Duedate > Present date & NotificationLog.DueDate-Present date < 8 days
NotificationLog.Duedate > Present date & NotificationLog.DueDate-Present date > 8 days
Using the above counts I need to create a column Chart which with the three categories in X axis and Days marked in Y axis.
As of now I get the NotificatonLog.Duedate in a dataset with several other columns . How Can i proceed from this point and accomplish my requirement .
Thanks !
You need to set up an approriate expression-based field to group on.
I have a simplified Dataset to replicate your issue:
I have added a Calculated Field to the Dataset, called DuedateGroup:
The expression is:
=Switch(Fields!Duedate.Value < Today(), "Overdue"
, Fields!Duedate.Value > Today() and Fields!Duedate.Value < DateAdd(DateInterval.Day, 8, Today()), "Near Due"
, Fields!Duedate.Value > Today() and Fields!Duedate.Value > DateAdd(DateInterval.Day, 8, Today()), "Far Due")
i.e. the three groupings you require.
Now you can just use the new field in the Chart:
Looks OK to me.
If you didn't want to set up a Calculated Field, you could add the group expression directly into the Category Group at the Chart level, but I like the Calculated Field option.

Grouping Unix Timestamp by Day Producing Unevenly Spaced Groups

I'm using a MySQL query to pull a range of datetimes as a Unix Timestamp (because I'll be converting them to Javascript time). I'm grouping by 'FROM_UNIXTIME' as below:
SELECT
UNIX_TIMESTAMP(DateAndTime) as x,
Sum(If(Pass='Pass',1,0)) AS y,
Sum(If(Pass='Fail',1,0)) AS z,
Sum(If(Pass='Fail',1,0))/(Sum(If(Pass='Pass',1,0))+Sum(If(Pass='Fail',1,0))) AS a,
cases.primaryApp
FROM casehistory, cases
WHERE DATE_SUB(CURDATE(),INTERVAL 80 DAY) <= DateAndTime
AND cases.caseNumber = casehistory.caseNumber
AND cases.primaryApp = 'Promo'
GROUP BY FROM_UNIXTIME(x, '%Y-%m-%d')
While I'd expected my timestamps to be returnd evenly spaced (that is, same amount of time between each day/group), I get the following series:
1300488140, 1300501520,
1300625099, 1300699980
All the other data from the query is correct, but because the spacing of the timestamps is irregular, a bar chart based on these stamps looks pretty awful. Perhaps I'm doing something wrong in the way I apply the grouping?
Thank you for the reply. My query 'made sense' in that it produced that could be plotted (the grouping was done on the x alias for the dateandtime value), but the problem was that pulling a Unix timestamp from the database and grouping by day returned a series of timestamps that did not have equal distance between them.
I solved this by pulling only the day (without the time) from the datetime MySQL field, then - in PHP - concatenating an empty time to the date, converting the resulting string to a time, then multiplying the whole shebang by 1000 to return the Javascript time I needed for the charting, like this:
x = x . ' 00:00:00';
x = strtotime(x) * 1000;
The answer put me on the right track; I'll accept it. My chart looks perfect now.
Question is very confused.
Your SQL statement makes no sense - you are grouping by entities not found in the select statement. And a bar chart plots an ordered set of values - so if there's something funny with the spacing then its not really a bar chart.
But I think the answer you are looking for is:
SELECT DATE_FORMAT(dateandtime, '%Y-%m-%d') as ondate
, SUM(IF(Pass='Pass',1,0)) AS passed
, SUM(IF(Pass='Fail',1,0)) AS failed
, SUM(IF(Pass='Fail',1,0))
/(SUM(IF(pass='Pass',1,0))+SUM(IF(Pass='Fail',1,0))) AS fail_pct
, cases.primaryapp
FROM casehistory, cases
WHERE DATE_SUB(CURDATE(),INTERVAL 80 DAY) <= dateandtime
AND cases.casenumber = casehistory.casenumber
AND cases.primaryapp = 'Promo'
GROUP BY DATE_FORMAT(dateandtime, '%Y-%m-%d')
ORDER BY 1;
And if you need Unix timestamps, wrap the above in....
SELECT UNIX_TIMESTAMP(STR_TO_DATE(CONCAT(ilv.ondate, ' 00:00:00'))) AS tstamp
, passed
, failed
, fail_pct
, primaryapp
FROM (
...
) AS ilv
Note that you'll still get anomolies around DST switches.
C.