SSRS expression for current month = 'Current' - reporting-services

First off I'm very new to SSRS and expressions are a steep learning curve.
I'm trying to write an expression to say if current month show text 'Current' else 'Past'. I've tried a few things like Month(Now()) = "Current" but can't get it to work.

Isn't it always the current month? You need to be comparing another date to the current month.
I think what you want is if a particular date field in your data is within the current month then show CURRENT, otherwise show PAST.
=IIF(FORMAT(Fields!END_DATE.Value, "MMyyyy") = FORMAT(TODAY, "MMyyyy"), "Current", "Past")
I use the FORMAT function to format the dates into month/year format - this eliminates the days so that it's just comparing the year and month.
The expression reads as
If the month/year of the END_DATE field is equal to the month/year of
the current day, then return the string CURRENT else return PAST.
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/expression-examples-report-builder-and-ssrs?view=sql-server-2017

Related

Week To Date Based Off Current Date

I am looking for an expression that will allow to me find the date of Monday of the week of my Date Field, to be used in a filter for a tablix.
Example, my date field today is 22/01/2019. I would like an expression that will return 21/01/2019. If the date was 26/01/2019, it should still return 21/01/2019.
For next week 31/01/2019 would return 28/01/2019.
Week starting Monday going to Sunday.
If its also possible for a similiar expression but to find the beginning of the month as well?
Is that possible?
Many thanks
To get the date of last Monday that occurred you can use something like
=Today.AddDays(1-WeekDay(Today(),FirstDayOfWeek.Monday))
and for the first of the month its just
=DateSerial(Year(Today()), Month(Today()), 1)
Both the above are based on the today() function, if you need them based on a date parameter, then the expression is a little different but your question stated "today".
monday of the week use the following expression:
DateAdd("d",DatePart(DateInterval.WeekDay,Fields!myDatefield.Value,0,0)+1,Fields!myDatefield.Value)
first day of the month use the following expression:
=DateAdd("d",-(Day(Fields!myDatefield.Value)-1), Fields!myDatefield.Value)

SSRS select parameter month and change par. first and last day of this month

i need to create parameter list of months and then (after select) recalculate two others paramateres in date format ([first day] and [last day]) of this month, can you please help me?
You are querying a database server to generate the list of months, although there's no need to do that. I suggest to rather create a list of months in the report and let the report calculate the month's names, so the language depends on the Language setting of the report (which can be the language configured in the user's browser).
For example, to calculate the Label for the Value 1, use an expression like =MonthName(1).
The Parameters FirstDay and LastDay (or just the values whenever you need them) can be calculated using these expressions:
FirstDay: =DateSerial(Today.Year, Parameters!Month.Value, 1)
LastDay: =DateSerial(Today.Year, Parameters!Month.Value, 1).AddMonths(1).AddDays(-1)

Current and Previous Month Revenue in Report

In Access 2013, I have a report showing revenue for each month of the year. I was success in getting a formula to name the previous month:
=Format$(DateAdd("m",-1,([ApptDate])),"mmmm",0,0)
What I am trying to get, is the revenue for the previous month for comparison, like a distribution chart. This is as close as I have gotten to something working, but the sum of the revenue for the previous month is too low (maybe only for a day's revenue?) Could anyone please help me put the following formula in the right order with right parameters to get the date needed?
=Sum(DateAdd("m",-1,([revenue])))
If I understood your problem correctly, you could use the DSum function by setting as criteria the month of the date to the previous month.
=DSum("[revenue]","YourTableName","Month([ApptDate])=" & Month(DateAdd("m",-1,Date())))

Comparing todays date against first day of the week

I am trying to set a default parameter value in SSRS report. I want to test the current date to see if it equals the first day of the week (in my case Monday). If it is the first day of week, then I want the default value to be current date minus 2 days, if it is not the first day of the week then I want the default value to be current date minus 1 day.
I seem to have a syntax problem but it doesn't tell me where. My parameters are StartDate and EndDate.
this is what I've tried:
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today(),DateAdd("d",-1,today())
this is the generic error I get:
The value expression for the report parameter 'StartDate' contains eror:[BC30201] Expression expected.
Where am I going wrong?
You are trying to use Sql syntax in a SSRS VBA expression. SSRS VBA allows very similar expressions for date manipulation to Sql, the main difference being the use of the DateInterval enum.
So your expression needs to use VBA syntax:
=IIF(Weekday(Today, FirstDayOfWeek.Monday) = 1, DateAdd(DateInterval.Day, -2, Today), DateAdd(DateInterval.Day, , -1, Today))
It appears that you are missing a closing parentheses after the first logical part of the if statement and another to close the statement.
=iif(weekday(Today(),FirstDayOfWeek.Monday)==1,DateAdd("d",-2,today()),DateAdd("d",-1,today()))

How to get current month name in SSRS?

I need current month name as default perameter name in my ssrs report. How can I get current month name using an ssrs expression?
For example "27-09-2012" would become "September"
and one more i need....
27-09-2012 to previous month name as well (August)
First question:
=MonthName(Month(Fields!datefield.Value))
Second question:
=MonthName(Month(DateAdd("m", -1, Today())))
I think the second question answer might be something like that, first converting the date to month then subtracting 1 from the month value and then converting it to month name.
Further reading:
SSRS Reports get Month name from Month Index or from date
Converting month number to month name in reporting services
OFF: I would change the date format you are using to 2012-09-27 as it works in every setting and should give you peace of mind when converting date formats.
Don't subtract 1 b/c it won't work for January.
Use this:
MonthName(Month(DateAdd("m", -1, CDate(Today))))
As a note, I tried the suggestion of =MonthName(Month(today())). What I would get is #error for whatever field the expression was in. However, =MonthName(str(Month(today()))) worked for me. I am unsure of whether or not the MonthName method changed to require a string or if it is some issue with my program. Just figured I would post this in case anyone else was having the same issue.
For Previous Month i found universal way : =MonthName(Month(CDate(Today()))-1,False) for SEPTEMBER (Full Month Name) 'OR'
=MonthName(Month(CDate(Today()))-1,True) for SEP (Short Month Name)