Week To Date Based Off Current Date - reporting-services

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)

Related

SSRS Expression for getting current week Sunday-Saturday

I am looking to make a report that gets the current week from sunday to saturday, i was thinking oh the headers of it having the date of the current week of running the report, does anyone know how to do that?
I assuming what you are asking is how to filter your dataset to show only records within the same week as the current week?
if so then you can do something like this
=WEEK(today()) = WEEK(Fields!myDateField.Value)
This will return True if the week is in the same week as the current week.
For more info on the WEEK function see here
https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008/aa337345(v=sql.100)

SSRS expression for current month = 'Current'

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

SSRS expression to get same month through today but for last year?

For example I would like the expected output to be 8/21/2018.
I have an expression to get the month of August of 2018 below, but not sure how to modify to get through the same date instead of returning the full month.
=DateAdd(DateInterval.Month, -12, DateAdd(DateInterval.Day,-Day(Today())+1,Today()))
If I get this correctly you want one year ago from a given date with todays day?
'Today: 8/23/2019
'Input: 8/21/2019
'Output: 8/23/2018
That would be this expression:
=DateSerial(Year(DateAdd("yyyy", -1, CDate("8/21/2019"))),
Month(CDate("8/21/2019")),
Day(Today()))

SSRS - weekday name

any advice appreciated
I have as a column heading the expression =WeekdayName(weekday(fields!date.value))
This returns the day of the week, however, it is returning a day of the week one day in advance, eg when I put Monday's dates in the parameter it shows as 'Tuesday' in the report.
My question is can the above expression be tweaked to show the WeekdayName one day before, eg =WeekdayName(weekday(fields!date.value -1)) ? I tried this but got an error.
Thanks.
So you want to subtract one day from the your incoming date then you can use the
= DateAdd("d", -1, yourdateField)
This way you can subtract the any number of days from your date.
But did you try to see why it is giving the day of previous date. Do check the system date time or else check with the
=WeekdayName(weekday(Today()))
and see if it gives you the correct day of week for current date.
Weekday and weekdayname functions have both another optional argument for defining the starting day of the week.
Problem is the 2 functions don' t default this argument to the same value so depending on your server settings you should explicitly set the second argument of these functions.
No need to invoke a date function. As the weekday() function returns and integer you can offset the result and use the Mod operator to keep it in bounds:
=WeekdayName((weekday(fields!date.value)+5) Mod 7)+1)
The parenthesis are important to ensure the addition comes first.
Just for reference:
OP asked again because of the weekday offset and this is the correct provided solution.
=WeekdayName(weekday(Today())) gives me tomorrow
=WeekdayName(Weekday(Today(),FirstDayOfWeek.System))

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)