SSRS Expression count records with date passed - reporting-services

In SSRS I am trying to create an expression that counts all records that have been scheduled for the end of today. How can is this possible?
=Count(IIF(Fields!scheduledendValue.Value <= Today, 1, 0))
Many thanks for help

Your logic is good, but your formula isn't. The "Today" function requires open and closing parentheses. Try this:
=Sum(IIF(Fields!scheduledendValue.Value <= Today(), 1, 0))

Related

SSRS Sum Values Based on Earliest Date

I'm trying to sum a net balance based on the earliest date in an SSRS report. In this case there are only 2 dates, but there can be more dates not more than 7 days.
Here's a sample of my data:
Here's what I'm trying to get with the earliest date of 10/26/15:
I've tried the following code, but not able to get this to work:
=Sum(IIf(DateDiff("d",Fields!SettleFullDate.Value,today())>=7
and DateDiff("d", Fields!SettleFullDate.Value, today())<7
and Fields!SETTLEBALANCE.Value>0), Fields!SETTLEBALANCE.Value, 0)
Update: I tried the code below and keep getting an error on the report. Could it be that I need to change the date field to an integer?
Thanks in advance for your help!
To compare the sum of values of two dates, the maximum and minimum in a set you can use the following equation
=Sum(iif(Fields!myDate.Value = Max(Fields!myDate.Value), Fields!myVal.Value, 0))
-Sum(iif(Fields!myDate.Value = MIN(Fields!myDate.Value), Fields!myVal.Value, 0))
This Sums all the values that match the maximum date in the dataset together, and sums all the values that match the minimum date in the dataset together, and takes one from the other.
It is irrespective of which dates you ask to be received, the above approach will work only against the records that you return to SSRS. So if you have a filter (WHERE clause) to return records between Date1 and Date2 this will still apply (Note - don't actually use 'Between' in the query)
Rather than using the maximum and minimum dates as listed here, you could also calculate a date similar to your original approach using
dateadd("d", -7, Fields!MySpecificDate.Value)
And insert that to the expression above.
Hopefully this is what you require - if not please let me know.

Query/Expression for Previous Month

Used as an expression in Access 2010, the below returns, for example, AUG15.
Left(MonthName(Month(Date())),3) & Right(Year(Date()),2)
How do I modify this to return the previous month, i.e. JUL15?
Start from the DateAdd expression which #Sam suggested ...
? DateAdd("m", -1, Date())
7/13/2015
Next use Format to present it as 3-letter month plus 2-digit year ...
? Format(DateAdd("m", -1, Date()), "mmmyy")
Jul15
If you want the month in all caps, feed the previous expression to UCase ...
? UCase(Format(DateAdd("m", -1, Date()), "mmmyy"))
JUL15
Note those examples are from the Access Immediate window, but those expressions (without ?) will work the same in your query.
You should look at the DateAdd function:
DateAdd ( interval, number, date )
Depending on your exact requirements, you could use it to substract a month from the current date like so:
DateAdd(m, -1, Date())
...or to build upon your expression:
Left(MonthName(Month(DateAdd(m, -1, Date()))),3) & Right(Year(DateAdd(m, -1, Date())),2)
to get records on same day of last month,eg. today is 19/12/21,and get records on 19/11/21 , you can use parameter query and enter the date required.
If every records of last month, ie from 1/11/21 to 30/11/21, two columns in query should be created to identify the month and year required. Make it clear,2 columns in query m:month(date()) and y:year(date()) and in criteria row put criteria of month and year required. If for last month criteria for m column is IIF(month(date())=1,12,month(date())-1), for y column is IIf(month(date())=1,year(date())-1,year(date())).
IIF is for when current date is in January.

Table filter in Report Builder DateDiff

I want to add a filter to a table in Report Builder. I want to get only the records from the last 12 hours. I have tried this, but it doesn't work.
DateDiff(HOUR,TimeOfDay(),Fields!Modified.Value) <=12
Any ideas ?
I found the solution:
=Iif(DateDiff(DateInterval.Hour, Fields!Modified.Value, Now()) <= 12, 1, 0)

how to do a sum iff expression for datepart m in last month

I am trying to write an expression to count the number of requests within a specific month from a year's worth of data.
I have tried:
=sum(iif((datepart("M",Fields!RequestDate.Value)) = (datepart("m",Now(-1))),1,0))
and many more different versions. Can someone point me in the right direction?
It seems in your example you're counting events from last month? I'm not sure what Now(-1) is trying to calculate in your example.
Anyway, this example worked for me in identifying counts from last month:
=Sum(IIf(DatePart("m", Fields!RequestDate.Value) = DatePart("m", DateAdd("m", -1, Now()))
, 1
, 0))
You can update the DateAdd("m", -1, Now()) part of the expression to set the month you want to update against.

SSRS: Expression to filter by datepart

I have a dataset which contains phone data for a given period, i need to filter this data based on the hour of the day so i can use this in a chart which shows the peak periods.
So far, i have this expression:
=Count(IIF(DatePart("h", Fields!CallStart.Value = 7), Fields!ID.Value, 0))
So, what i had hoped this expression would do is replicate this SQL Query:
select * from PhoneData
where MONTH(callstart) = 7 and YEAR(callstart) = 2012 and DATEPART(HH, callstart) = 7
and Direction ='i' and Part1Device not like 'v%' and Continuation = '0'
The month and year are set in the dataset query.
Suffice to say, the expression doesn't work and i can't quite figure out why.. any help would be greatly appreciated.
Looks like your closing bracket for the DatePart function is in the wrong place. Try this.
=Sum(IIF(DatePart("h", Fields!CallStart.Value) = 7, 1, 0))