SSRS optional cascading parameter for date - sql

I have a report that I am attempting to setup a subscription for. The subscriber would like the report on the 4th every month for the previous month's end date. e.g ran today would return the data through 10/31.
I would like to create this report so that there is a cascading parameter that would be labeled Use previous month end date to set the end date to the subscription date when flagged on and allow the user to enter a date when flagged off. so that i can use this parameter to create the dynamic subscription but allow anyone else hitting it through the report server to enter their own date.
Is this possible?

You don't need the UsePriorMonth parameter - just default the date range to be the prior month and allow users to change it if they want.
So your DateFrom parameter Default Value expression is:
=DateAdd(DateInterval.Month, -1, DateAdd(DateInterval.Day, 1-Day(Today), Today))
and your DateTo parameter Default Value expression is:
=DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Day, 1-Day(Today), Today))

Related

Adjust Date values based on a parameter value in SSRS

We have a SSRS report with Year , Start-Date, End-Date Fields ( Start-Date and End-Date are Date controls and Year is a Combo Value). I need the value of Start-Date and End-Date to be Restricted based on Year value.
For eg: If the Year value is 2016, then the Start-Date and End-Date value should be between 01/01/2016 and 12/31/2016.
How to do this in SSRS?. Please Help
I'd use the Year value to determine if StartDate and EndDate are dates between Year. Using a expression you can get the year from StartDate and compare it against Year value, based on that comparision you can set another parameter (StartDateHidden) which is hidden for users and populated depending on the comparision.
Expression for StartDateHidden.
=IIF(
Paramaters!StartDate.Value.Year = Parameters!Year.Value,
Paramaters!StartDate.Value,DateSerial(Parameters!Year.Value,1,1)
)
Note it populates StartDateHidden with the StartDate value if it is a date in Year value, otherwise it will set the first date of the Year value.
You can use any default value for cases when StartDate is not in the Year value.
Expression for EndDateHidden.
=IIF(
Parameters!EndDate.Value.Year = Parameters!Year.Value,
Parameters!EndDate.Value,DateSerial(Parameters!Year.Value,12,31)
)
Let me know if this helps.
This can be accomplished with one drawback. Your date picker will no longer be a calendar it will be a drop down list with the dates.
Create a query that produces the list of dates you are looking for and add it to the report as a data set. Then in the properties of your Start-Date and End-Date report parameters click on the default values pane. Choose get values from query, select the appropriate dataset, value field, and label field.
After that when you run the report you will have a drop down with the list of dates your query returned. Just make sure you make your dates query dependant on the year report parameter.

(Parameters) Can a date generate a day in SSRS Report Builder 3.0?

Parameters: Select day of week (mon, tue, wed Etc.), Select the date of promotion (ex. 04/04/2014). I would like to eliminate the step of choosing what weekday it is. Can the parameter realize date and day?(DATENAME(dw, tra.Date) = #DayOfWeek) and (tra.Date = #PromoDate) When I change the #DayOfWeek to #PromoDate I get the following error "Cannot read the next data row for the dataset AverageHI. (rsErrorReadingNextDataRow)"
First Change your Parameter Type to "Date" type. I guess your error causes of this.
If you want to get Day from date then use
=WeekdayName(2,True,0)
=WeekDayName(DatePart("w",Fields!BirthDate.Value),True,0)
=WeekDayName(DatePart(DateInterval.Weekday,Fields!BirthDate.Value),True,FirstDayOfWeek.System)

How to get month within a range vb2010

I just don't know how to go about this.
I designed a program that uses MS Access as its database. I have a field for month and year (the field data type is text) where user can register details. The program will register the month and year the user have chosen e.g month= September, year=2011.
My problem now is how to chose a range of data to view by the user using the month and year as a criteria e.g the User may want to view data range from (September 2011 to July 2013).
I couldn't figure out even how to try. Help will be highly appreciated.
Perhaps you could change your application logic to store the month and year as their respective numbers rather than text and change the field data types to numeric.
You could then construct a DateTime object from them, for example September would be 9 and you could use code like the following:
var startDate = new DateTime(year, month, 1); // get year and month as integers from database, uses the first as the date
var endDate = new DateTime(year, month, 10); // change the date but keeps the month and year the same
var endDate2 = startDate.AddMonths(1); // adds 1 month to the date
Alternatively, you could try using a calendar control to allow the user to select two dates instead of building it from a number of fields. Depending on what you are using this could be achieved a number of ways, for example in ASP.Net or WPF you could use two calendar controls and just use their SelectedDate properties as your range.
A range is from a startpoint until an end point. For the startpoint you can add automatically the first of Month. For the endpoint is it more complicated because there is no fix endpoint. What you can do is following:
Write an array that contains for each month the days (e.g. 30 or 31). Except for Febrauary there is a fix pattern.
for Febrauary use the selected year to check is the year a leap year or not. If not add 28, else add 29.
After that create the date string for your SQL:
Startdate 1.9.2011. Do for the entdate the same.
After that, I think you can use the keyword between in your SQL query.
You can assume that everything is entered on the first day of each month. I would pull the information using a query to the database.
select * from [tablename] where DateSerial([colYear], [colMonth], 1) between DateSerial([fromYear], [fromMonth], 1) and DateSerial([toYear], [toMonth], 1)
In this question are some ways to do this:
First. Filter the dates in a range assuming that you use a date like '07-12-2012'
i.e. September 2011 to July 2013
Where DateColumn > '09-01-2011' and DateColumn < '07-31-2013'
OR
Specify a Date and a Year
Where month(DateColumn)='1' and year(DateColumn)='2016'
Note:
There are many ways to do this.
You can Manipulate your statement depending on your desired output.

including the datediff expression within the table in a row in MS Access 2007

I have a 3 column in my table as start date, end date and total days. All I need it the following
How to set the current date in the start date column
Another question is how to get the date difference and the result should be displayed in another column called total days.
The start date can be set so that the default value is the current date, date(), when a record is created. You do that in design window. Since the other two fields are clearly filled in at a later date the mechanism for input can use the same function as a default end date. The difference is then calculated between current date and start date. If you use a form as the mechanism for update, the expressions are set as default values. If you use an update query, those expressions would be set as the updating values.

How to group by week specifying end of week day?

I need to run a report grouped by week. This could be done by using group by week(date) but the client wants to set the day of the week that marks the end of week. So it can be Tuesday, Wednesday etc. How can I work this into a group by query?
The datetime column type is unix timestamp.
The WEEK() function takes an optional second parameter to specify the start of the week:
This function returns the week number for date. The two-argument form of WEEK() enables you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range from 0 to 53 or from 1 to 53.
However, it can only be set to Sunday or Monday.
UPDATE: Further to the comments below, you may want to consider adding a new column to your table to act as a grouping field, based on WEEK(DATE_ADD(date INTERVAL x DAY)), as suggested in the comments. You may want to create triggers to automatically generate this values whenever the date field is updated, and when new rows are inserted. You would then be able to create a usable index on this new field as required.