简体   繁体   English

SSRS表达式-嵌套的IIF,默认日期

[英]SSRS Expression - Nested IIF, default date

I have an SSRS report with a date parameter which defines the start of the week that we wish to report on. 我有一个带有日期参数的SSRS报告,该参数定义了我们希望报告的一周的开始时间。 I want the default date for this parameter to display as follows based on a nested IIF statement that uses the current day of the week to determine which date the parameter should display as default (I have included example dates for January in the brackets): 我希望此参数的默认日期基于嵌套的IIF语句显示如下,该语句使用一周的当前日期确定该参数应显示为默认日期(括号中包括一月的示例日期):

  • Monday (18th) = Monday Last Week (11th) 星期一(18日)=上周一星期一(11日)
  • Tuesday (19th) = Monday Last Week (11th) 星期二(19日)=上周一星期一(11日)
  • Wednesday (20th) = Monday Last Week (11th) 星期三(20日)=上周一星期一(11日)
  • Thursday (21st) = Monday Last Week (11th) 星期四(21日)=上周一星期一(11日)
  • Friday (22nd) = Monday This Week (18th) 星期五(22日)=本周星期一(18日)
  • Saturday (23rd) = Monday This Week (18th) 星期六(23日)=本周星期一(18日)
  • Sunday (24th) = Monday This Week (18th) 星期日(24日)=本周星期一(18日)

I have attempted to write an expression to accomplish this but so far I have been unable to get the parameter to display as I require. 我试图编写一个表达式来完成此操作,但到目前为止,我仍无法根据需要显示该参数。 The expression I have written is: 我写的表达式是:

=IIF(DateInterval.Weekday = 1, 'Monday = Monday Last Week
DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)),
    IIF(DateInterval.Weekday = 2, 'Tuesday = Monday Last Week
        DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)),
            IIF(DateInterval.Weekday = 3, 'Wednesday = Monday Last Week
                DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)),
                    IIF(DateInterval.Weekday = 4, 'Thursday = Monday Last Week
                        DateAdd(DateInterval.Day, 2-WeekDay(Today), DateAdd(DateInterval.Day, -7, Today)),
                            IIF(DateInterval.Weekday = 5, 'Friday = Monday This Week
                                DATEADD("d", 1 - DATEPART(DateInterval.WeekDay, Today,FirstDayOfWeek.Monday), Today),
                                    IIF(DateInterval.Weekday = 6, 'Saturday = Monday This Week
                                        DATEADD("d", 1 - DATEPART(DateInterval.WeekDay, Today,FirstDayOfWeek.Monday), Today),
                                            IIF(DateInterval.Weekday = 7, 'Sunday = Monday This Week
                                                DATEADD("d", 1 - DATEPART(DateInterval.WeekDay, Today,FirstDayOfWeek.Monday), Today),
                                                Today
                                            )
                                    )
                            )
                    )
            )
    )
)

Is what I am attempting possible? 我尝试的可能吗? And if so where am I going wrong? 如果是这样,我在哪里出错? Also, I am aware that comments will cause the expression to error, I have added comments to the example code to make it more readable. 另外,我知道注释会导致表达式出错,我在示例代码中添加了注释,以使其更具可读性。

The following will work for you: 以下将为您工作:

=DateAdd("ww", Datediff("ww", CDate("1900-01-01"), DateAdd("d", -5, Today)), CDate("1900-01-01"))

The premise is that it finds the number of weeks between a fixed point in time (1st Jan 1900) and 5 days ago (to get the default week to change on Friday), then adds that number of weeks to the same fixed point giving the start of the current week, or the previous week if it is Monday to Thursday. 前提是找到固定时间点(1900年1月1日)到5天之前的周数(以获取默认的星期几在星期五更改),然后将该周数添加到相同的固定点,从而得出当前一周的开始,如果是星期一至星期四,则为前一周。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM