SSRS - 如何使用 SSRS 表达式提取上周五

SSRS - How to pull previous Friday with SSRS expression

我需要帮助来提取之前的工作日并排除 SSRS 中的周末。我使用下面的代码,但是这个代码看起来并没有超过周末。

下面是我常用的代码:

=DateAdd(DateInterval.Day
, Switch(DatePart(DateInterval.WeekDay, Today()) = 2, -3
,DatePart(DateInterval.WeekDay, Today()) = 1, -2
,True, -1)
, Today())

有没有人对如何编写 SSRS 表达式来查看周末并仅提取工作日有任何想法?

您可能设置了不同的一周第一天(取决于地区或服务器的配置方式)。无论此设置如何,在 DatePart 函数中显式设置 FirstDayOfWeek 应该会给出一致的结果:

=DateAdd(DateInterval.Day
    , Switch(DatePart(DateInterval.WeekDay, Today(), FirstDayOfWeek.Sunday) = 2, -3
        ,DatePart(DateInterval.WeekDay, Today(), FirstDayOfWeek.Sunday) = 1, -2
        ,True, -1)
    , Today())

如果您想在报告 运行 星期一时将日期参数默认为星期五(否则默认为前一天),试试这个:

=DateAdd(DateInterval.Day, IIf(DatePart(DateInterval.Weekday, Today) = 2, -3, -1), Today)

这可能就是您真正需要的。

以下表达式可用于将日期参数默认为前一个星期五,无论报告 运行 是一周中的哪一天。这对每周报告有一定的价值。

=DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, DateAdd(DateInterval.Day, 1, Today), 0, 0)), Today)

继续探索这个问题并与其他人一起工作...这就是我们想出的方法来查看前一个工作日并在周一提取报告时排除周末。此表达式将添加到日期参数。

=Switch(WeekdayName(DatePart("w", Today)) = "Wednesday",DateAdd(DateInterval.Day
    , Switch(DatePart(DateInterval.WeekDay, Today()) = 2, -3
 ,DatePart(DateInterval.WeekDay, Today()) = 1, -2,True, -2)    , Today()),

    WeekdayName(DatePart("w", Today)) = "Thursday",DateAdd(DateInterval.Day
    , Switch(DatePart(DateInterval.WeekDay, Today()) = 2, -3
 ,DatePart(DateInterval.WeekDay, Today()) = 1, -2,True, -2)    , Today()),

    WeekdayName(DatePart("w", Today)) = "Friday",DateAdd(DateInterval.Day
    , Switch(DatePart(DateInterval.WeekDay, Today()) = 2, -3
 ,DatePart(DateInterval.WeekDay, Today()) = 1, -2,True, -2)    , Today()),

    WeekdayName(DatePart("w", Today)) = "Saturday",DateAdd(DateInterval.Day
    , Switch(DatePart(DateInterval.WeekDay, Today()) = 2, -3
 ,DatePart(DateInterval.WeekDay, Today()) = 1, -2,True, -2)   , Today()),

    WeekdayName(DatePart("w", Today)) = "Sunday",DateAdd(DateInterval.Day
    , Switch(DatePart(DateInterval.WeekDay, Today()) = 2, -3
 ,DatePart(DateInterval.WeekDay, Today()) = 1, -2,True, -3)    , Today()),

    WeekdayName(DatePart("w", Today)) = "Monday",DateAdd(DateInterval.Day
    , Switch(DatePart(DateInterval.WeekDay, Today()) = 2, -3
 ,DatePart(DateInterval.WeekDay, Today()) = 1, -2,True, -4)    , Today()),

    WeekdayName(DatePart("w", Today)) = "Tuesday",DateAdd(DateInterval.Day
    , Switch(DatePart(DateInterval.WeekDay, Today()) = 2, -3
 ,DatePart(DateInterval.WeekDay, Today()) = 1, -2,True, -2)    , Today())

)

这个表达式还会拉出前一个工作日,这是我最近一直在使用的。只需使用此代码更新您的日期参数。

=DateAdd("d",Switch(DatePart("w", Today) = 2,-3,DatePart("w", Today) = 1,-2,True,-1),Today)