SSRS- Issue with iif containing monthname function - reporting-services

I have a data set that I am trying to force everything >12 months ago into a single group. I am trying to do this with a SQL case when that assigns all months and year >12 months ago a int value of 0 but when I try to put this into SSRS it doesnt work.
I have been trying to use this formula but it does not work unless I remove the 'MonthName' function.
=iif(Fields!ASGN_SUB_DUE_MONTH.Value > 0,monthname(Fields!ASGN_SUB_DUE_MONTH.Value) & " " & Fields!ASGN_SUB_DUE_YEAR.Value
,"More than 12 months ago")
But this formula works
=iif(Fields!ASGN_SUB_DUE_MONTH.Value > 0,
monthname(iif(Fields!ASGN_SUB_DUE_MONTH.Value > 0 and Fields!ASGN_SUB_DUE_MONTH.Value < 13, Fields!ASGN_SUB_DUE_MONTH.Value,1))
& " " & Fields!ASGN_SUB_DUE_YEAR.Value
,"More than 12 months ago")
Does anyone know why and how I can resolve. The second function works but I'm not comfortable leaving it in the reporting incase the second part of the imbedded iif ever functions.
Thanks in advance

The issue is related to my case statement and how the iif processes in SSRS, from my subsequent research.
The true statement needs the imbedded iif because its evaluating all entries vs all parts of the expression, so even when i have "Month" values of -1 or 0 that wouldn't hit the iif portion with MONTHNAME() its still evaluating it and causing an error.

Related

Microsoft access Query IIF statement not returning what i want

I have the below query which is meant to only return lines that are less than the ETA Date.
When applying the criteria below it does return the lines in which the ETA Date is less than today, however it does return the other lines as well and i don't want that.
I just want it to return the lines in which dates are lower than today's date.
Overdue: IIf([PO ETA]<=Now(),DateDiff("yyyy",[PO ETA],Now()) & "year(s)" & DateDiff("m",[PO ETA],Now()) & "month(s)" & DateDiff("d",[PO ETA],Now()) & "day(s)")
I have tried to add something for the else statement but i can't seem to figure out what i should add.
You miss the criteria for that Overdue expression:
<>""

can't get SSRS 2008 IIF statement with DatePart to work

I'm getting an error when I use the statement below. I'm using an IIF statement to get the correct week number. The week numbers are different for 2016 than other years so my old expression is returning one week number later than it should -- the old: =DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.value).
what I have written but am getting an error and I cannot figure out what the problem is:
=IIF(=DatePart(DateInterval.Year, Fields!REQ_DATE.Value) =
“2016”,=DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value) –
1,=DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value))
basically, if the year of the field REQ_DATE is 2016, I want the WeekOfYear for REQ_DATE - 1; else just the WeekOfYear.
can anyone help me? thank you!
You don't have to use = for every function you call in an expression, use the = only once at the beginning of the whole expression.
Try:
=IIF(DatePart(DateInterval.Year, Fields!REQ_DATE.Value) =
"2016",DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value) –
1,DatePart(DateInterval.WeekOfYear, Fields!REQ_DATE.Value))

SQL Server Reporting Services Date/Sum weirdness

I have 2 columns next to each other in a report I'm building. They contain the same structure, with one small difference. One column looks back in time a little further then the other. I have verified that the data is there to be found. A row group below returns the rows using the same structure. Column A returns the correct data. Column B does not.
Column A Expression
=IIF(Format(Fields!IncomingInvoiceDate.Value, "yyyy-MM-dd") > DateAdd("d", -31, Now()), Sum(Fields!Value.Value), 0)
Column B Expression
=IIF(Format(Fields!IncomingInvoiceDate.Value, "yyyy-MM-dd") >= DateAdd("d", -61, Now()), Sum(Fields!Value.Value), 0)
I've tried every single variation I can find, and nothing returns the correct data. I'm on SQL Server 2012. Thanks for any help.
Put your IF inside the SUM instead of the other way around.
Something like this should work. You'll want to change both the 30 day and 60 day expressions to fit this pattern.
Sum(
IIF(Format(Fields!IncomingInvoiceDate.Value, "yyyy-MM-dd") >= DateAdd("d", -61,Now()), Fields!Value.Value, 0)
It turns out nothing has worked, and I redesigned the query completely. Thanks all.

Access DSUM with multiple variables including dates derived from date parts

Really hoping for guidance.
I'm calculating a running 3 month total in an Access query. two of the DSUM variables are strings and the third is a date that i derive from date parts.
The string variables I passing in are working fine, but I'm having a hard time getting the date range to work in the statement.
Here's what's working:
Running_TOT: DSum(" [SumOfCNTRCTL_ADJSTMT_AMT] ","tbl_processed_accts","[PYR]='" & [PYR] & "'and [PT_TYPE_CD]='" & [PT_TYPE_CD] & "'")
The following needs to be added in a third and clause:
DateSerial([DSCHRG_YR],[DSCHRG_MNTH],1)
BETWEEN
DateAdd("m",-2,DateSerial([DSCHRG_YR],[DSCHRG_MNTH],1))
AND
DateAdd("m",1,DateSerial([DSCHRG_YR],[DSCHRG_MNTH],1))-1
I think I've read every DSUM post on the internet looking for ideas. Eternal gratitude for anyone who can lend a hand getting the syntax right..
Thanks.

How to set the year part of a field using a query

Evening,
I have created a query that is suppose to change ONLY the year part of a Date/Time field to 1900 when a person is 89 years or older. The query that follows compiles fine but when run it complains about a Type Conversion failure and removes the entire value from the records affected.
The query:
UPDATE tblTestForDOB
SET tblTestForDOB.[PT_BirthDate] = DateValue( (day([PT_BirthDate])/month([PT_BirthDate])/1900) )
WHERE Year(tblTestForDOB.[PT_BirthDate]) <= Year(Date())-"89";
According to the MS Help (F1 over the function):
The required date argument is normally a string expression representing a date from January 1, 100 through December 31, 9999. However, date can also be any expression that can represent a date, a time, or both a date and time, in that range.
Is that not what I'm doing? I also tried placing the " " & before the values inside the DateValue function and that did the same thing
(to ensure that it was a string that was passed)
So how do I go about it? Should I use CDate to convert the value to a Date and then proceed that way? If so what is the correct syntax for this?
Thanks
P.S The field is of Short Date format. Also note that I don't want to take the long way around and use VBA for the whole thing as that would involve opening record sets and so on...
It appears you're trying to give DateValue a string, but that's not what's happening. There may be more going on that I don't understand, so I'll just show you an Immediate window session which may contain something you can build on.
PT_BirthDate = #1923-6-1#
? PT_BirthDate
6/1/1923
? DateDiff("yyyy", PT_BirthDate, Date())
90
' this throws error #13: Type mismatch ...
? DateValue( (day([PT_BirthDate])/month([PT_BirthDate])/1900) )
' it will work when you give DateValue a string ...
? DateValue("1900-" & Month(PT_BirthDate) & "-" & Day(PT_BirthDate))
6/1/1900
' or consider DateSerial instead ...
? DateSerial(1900, Month(PT_BirthDate), Day(PT_BirthDate))
6/1/1900