[英]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). 我们有一个
SSRS
报告,其中包含Year , Start-Date, End-Date
字段(Start-Date和End-Date是Date
控件, Year
是Combo
值)。 I need the value of Start-Date and End-Date to be Restricted based on Year
value. 我需要根据
Year
值限制Start-Date和End-Date的值。
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
. 例如:如果Year值为
2016
,则Start-Date和End-Date值应介于01/01/2016
和12/31/2016
之间。
How to do this in SSRS
?. 如何在
SSRS
执行此操作? Please Help 请帮忙
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.
只需确保使日期查询取决于年报表参数即可。
I'd use the Year value to determine if StartDate
and EndDate
are dates between Year
. 我将使用Year值来确定
StartDate
和EndDate
是否为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. 使用表达式,您可以从
StartDate
获取年份并将其与Year
值进行比较,基于该比较,您可以设置另一个参数( StartDateHidden
),该参数对于用户是隐藏的,并根据比较结果进行填充。
Expression for StartDateHidden
. 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. 请注意,如果它是
Year
值中的日期,则使用StartDate
值填充StartDateHidden
,否则它将设置Year
值的第一个日期。
You can use any default value for cases when StartDate
is not in the Year value. 对于
StartDate
不在Year值中的情况,可以使用任何默认值。
Expression for EndDateHidden
. EndDateHidden
表达式。
=IIF(
Parameters!EndDate.Value.Year = Parameters!Year.Value,
Parameters!EndDate.Value,DateSerial(Parameters!Year.Value,12,31)
)
Let me know if this helps. 让我知道是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.