Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...