I am using Visual Studio 2012 and SQL Server 2012.
I have created two parameters, StartDate and EndDate, which are both Date/Time parameters.
In my EndDate parameter, I have set the Default Value to Today() in order to get today's date.
For my StartDate parameter, I want it to be based off the EndDate parameter in the following way. Whatever date the user selects as End Date, StartDate will be the date 24 months/2 years prior. (For example, if EndDate was Today (1/11/2017)...then StartDate would be 1/11/2015.)
In the expressions box, this is what I have so far for my default value for StartDate. =DateAdd(DateInterval.Year,-2,Today())
How do I get it, so that every time I change the EndDate, the StartDate updates accordingly to be 2 years prior?
Try this expression it will return 1/22/2015
=Date.Now.Date.AddYears(-2).AddDays(10)
Related
I am working on a report that I need to add a date range parameter. The field that I need to use in the datetime field, and I need to use the date portion from the field. I tried using the following, but the report returns no result.
cast(StartDateTime as date) between {?StartDate} and {?EndDate}
For the time being, I am using the Select Expert to sort the date range, but I have to manually enter the date in 'yyyy-mm-dd' format. Is there a way to set up the parameter, so that I can use the calendar to choose the dates?
I recommend to use one parameter field and set it to range and date instead of two.
With this you can use easily this formula:
{StartDateTime} = {?Parameter}
If you set the Parameter to Date instead of DateTime it will automatically check with the start of the day for the first range and the end of the day for the last range.
Is there an expression in SSRS where I can set the default parameters from 1 year ago on the first date thur the 1st day of the current month?
Example: Start Date 8/1/16 End Date 8/1/17
Thanks in advance!
I keep a cheat-sheet of common date calculations around, and then in my reports I'll create a new data set like the one below, using it to set the initial parameter values:
SELECT StartDate = DATEADD(YEAR, -1, CAST(DATEADD(dd,-(DAY(GETDATE())-1),GETDATE()) AS DATE))
, EndDate = CAST(DATEADD(dd,-(DAY(GETDATE())-1),GETDATE()) AS DATE)
Here's an example set of date calculations
I have a SSRS report that has typical Start Date / End Date parameters that will filter out Sales Order information based on the OrderDate field. With this report, I have a subreport. This subrebort is basically nothing more than an aggregation of the same info, by month. This aggregate information should be from the first day of the month, one year prior, through the last day of the End Date's parameters month. This does not take the main subreports Start Date parameter into consideration at all.
This is where it gets a little tricky. For example, lets say I made the start date / end date parameters on my main report:
10/15/2016 - 11/15/2016
(just remember, for this purpose, the start date is irrelevant)
I would want the subreport to show the sales totals, per month, for the ENTIRE month of December 2015 through the ENTIRE month of November 2016, even though my end date was 11/15/2016.
If I were to put in those same dates for my parameters in the report right now, for the aggregation of December 2015, I would only get sales from the 15th through the 31st. Currently I have my subreport to filter on the OrderDate by:
Fields!OrderDate.Value>= DateAdd(DateInterval.Month, -12,Parameters!EndDate.Value)
I know that this filter is not currently set up to have an end date for the parameter, just a greater than argument, which is wrong since I want the 12 month history to stop at the last day of the month for the month of my End Date parameter, but I don't know how to make that happen either.
I hope I have explained this well. Any help on this would be greatly appreciated.
You can set a filter to get only dates between a specific range in your subreport dataset, tablix and some visualizations:
In DataSet properties or Tablix Properties in the Filter tab use these settings:
In the Value textboxes you should use the expressions to calculate your date range.
StartDate
=DateSerial(Parameters!EndDate.Value.Year-1,Parameters!EndDate.Value.Month,1).AddMonths(1)
EndDate
=DateSerial(
Parameters!EndDate.Value.Year,Parameters!EndDate.Value.Month,1).AddMonths(1).AddDays(-1)
It should filter your data from 12/01/2015 to 11/30/2016 if your EndDate parameter is set to 11/15/2016
Let me know if this helps.
I have 2 parameters in my report to select a date range:
StartDate & EndDate
I want to hide the StartDate and allow users to just select the EndDate which should then dynamically change the start date to 1 year before the EndDate.
I need this to happen every time a user changes the EndDate changes.
I'm pretty sure I have to use cascading parameters, but I don't know how.
Any suggestions?
Yes, cascading parameters are the trick if you want to do this at the report level. (You could also handle this pretty effectively at the query level.)
First arrange the parameters in your report in order of dependence: EndDate should be be listed above StartDate. Use the up and down arrows to rearrange the parameters.
Set the StartDate parameter to be "Internal" and set the default value appropriately. Select "Specify values" and create a value of =DATEADD( DateInterval.Year, -1, Parameters!EndDate.Value )
Now you can use both #EndDate and #StartDate in your query without initializing them and they will be passed the SSRS value.
I am looking for help to accomplish following task in T-SQL:
I have a timezone, and I need to calculate an UTC datetime which is current date minus one month, but has 0 hours and 0 minutes in a given timezone.
Is this what you need?
Select Cast(Floor(Cast(DateAdd(month, -1, getutcdate()) as float)) as datetime)
SQL Server 2008 and later provides the datetimeoffset type that includes a timezone. You can change the timezone using the SWITCHOFFSET function to change timezone and the DATEADD function to add -1 month to the resulting value. Then you can convert to the DATE type to eliminate the time part.
select cast(DATEADD(month,-1,todatetimeoffset(GETUTCDATE(),'+02:00')) as DATE)