Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
584 views
in Technique[技术] by (71.8m points)

reporting services - How to set the previous "MONTH/YEAR" based on the TODAY() value in an SSRS expression

I am working in VS2017 and I am trying to define in my textbox expression the PREVIOUS "MONTH/YEAR" in SSRS. Today's date is 2021-01-06 and I'm trying in my SSRS expression to configure that and I'm not having any success. Any help/direction would be appreciated, thanks.

Here is the code that I've tried in my SSRS expression:

="Agent Report " & vbcrlf & "for: " & MonthName(Month(DateAdd("M",-1,Today.Date))) & " - " & 
    IIF(Today.Month = 1, (Year(DateAdd("Y",-1,Today.Date))), (Year(DateAdd("Y",0,Today.Date)))) 

When I execute the code above I'm getting this error in VS2017:

Severity Code Description Project File Line Suppression State Warning [rsRuntimeErrorInExpression] The Value expression for the textrun 'Textbox1.Paragraphs[0].TextRuns[0]' contains an error: Argument 'DateValue' cannot be converted to type 'Date'. C:Usersmsavoysource eposSSRS Reports_UpdatedSSRS Reports_UpdatedAgents Using a Rater Report.rdl 0

question from:https://stackoverflow.com/questions/65599064/how-to-set-the-previous-month-year-based-on-the-today-value-in-an-ssrs-expre

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I'm not sure where your error comes from, the expression evaluated without an error when I tried it. It did return, what I think, is the wrong answer though.

I simplified it to this...

="Agent Report " & vbcrlf & "for: " 
& MonthName(Month(DateAdd("M" ,-1,Today.Date))) 
& " - " 
& IIF(Today.Month = 1, Today.Year - 1, Today.Year)

This returned

Agent Report 
for: December 2020

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...