我创建了一个SSRS报告,该报告显示了来自OLAP多维数据集的数据。该报告中有一些参数,其中许多参数具有使用MDX查询检索到的“可用”和“默认”值。
报告中还有以下参数: @ Year,@ Month,@ Day
我使用昨天作为日期(NOW()-1)来计算这些参数,并从MDX查询中检索值。
WITH MEMBER [Measures].[Full Date] as 'NOW()-1'
MEMBER [Measures].[Day] as 'DAY([Full Date])'
MEMBER [Measures].[Month] as 'MONTH([Full Date])'
MEMBER [Measures].[Year] as 'YEAR([Full Date])'
SELECT
{[Full Date],[Day],[Month],[Year]} ON COLUMNS
FROM [CallCenter]
我需要将“ NOW()-1”日期替换为上一个工作日。
WITH MEMBER [Measures].[Full Date] as '[previous working day]'
在数据仓库中,我创建了一个存储过程来计算上一个工作日。
DECLARE @yesterday date
SET @yesterday = DATEADD(day,-1,@date)
select
today = @date
,todayname = DATENAME(WEEKDAY,@date)
,yesterday = @yesterday
,yesterdayname = DATENAME(WEEKDAY,@yesterday)
,day = CASE
WHEN DATENAME(WEEKDAY,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
WHEN DATENAME(WEEKDAY,@yesterday) = 'Saturday'
THEN DATEADD(day,-1,@yesterday)
-- **************************
-- LUNEDI' DELL'ANGELO
-- **************************
WHEN @yesterday = DATEADD(day,1,intern.GetEasterSunday (Year(@yesterday)))
THEN DATEADD(day,-3,@yesterday)
-- **************************
-- CAPODANNO
-- **************************
WHEN MONTH(@yesterday) = 1 and DAY(@yesterday) = 1
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- EPIFANIA
-- **************************
WHEN MONTH(@yesterday) = 6 and DAY(@yesterday) = 1
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- FESTA DELLA LIBERAZIONE
-- **************************
WHEN MONTH(@yesterday) = 4 and DAY(@yesterday) = 25
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- FESTA DEI LAVORATORI
-- **************************
WHEN MONTH(@yesterday) = 5 and DAY(@yesterday) = 1
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- FESTA DELLA REPUBBLICA
-- **************************
WHEN MONTH(@yesterday) = 6 and DAY(@yesterday) = 2
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- FERRAGOSTO
-- **************************
WHEN MONTH(@yesterday) = 8 and DAY(@yesterday) = 15
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- FESTA DI OGNISSANTI
-- **************************
WHEN MONTH(@yesterday) = 11 and DAY(@yesterday) = 1
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- IMMACOLATA CONCEZIONE
-- **************************
WHEN MONTH(@yesterday) = 12 and DAY(@yesterday) = 8
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- NATALE
-- **************************
WHEN MONTH(@yesterday) = 12 and DAY(@yesterday) = 25
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Sunday'
THEN DATEADD(day,-2,@yesterday)
ELSE DATEADD(day,-1,@yesterday)
END
-- **************************
-- SANTO STEFANO
-- **************************
WHEN MONTH(@yesterday) = 12 and DAY(@yesterday) = 26
THEN
CASE
WHEN DATENAME(weekday,@yesterday) = 'Monday'
THEN DATEADD(day,-3,@yesterday)
WHEN DATENAME(weekday,@yesterday) = 'Tuesday'
THEN DATEADD(day,-4,@yesterday)
ELSE DATEADD(day,-2,@yesterday)
END
ELSE @yesterday
END
我无法用存储过程的结果替换“ NOW()-1”日期。
我需要一些帮助。谢谢。
答案 0 :(得分:0)
您可以使用以下代码
member measures.t
as
case
when datepart('w', Now()) = 1 then Now()-2 //Sunday is 1 by default
when datepart('w', Now()) = 7 then Now()-1 //Saturday is 7 by default
else
Now()
end
但是,如果您想对维度实施相同的逻辑,请查看以下示例
with
member measures.t
as
case
when datepart('w', [date].[date].currentmember.name) = 1 then dateadd('d',-2,[date].[date].currentmember.name)
when datepart('w', [date].[date].currentmember.name) = 7 then dateadd('d',-1,[date].[date].currentmember.name)
else
cdate([date].[date].currentmember.name)
end
select measures.t
on 0,
[Date].[Date].[Date]
on 1
from [Adventure Works]
where
([Date].[Calendar Year].&[2012],[Date].[Month of Year].&[2])
结果(看看2月11日和12日)