当时间不在轴上时出现 ParallelPeriod 问题
ParallelPeriod issues when time is not on axis
此查询中计算的成员 [Amount LM](=amount last month)有什么问题?如果我在行上指定时间似乎有效,但如果我不指定时间则失败,即使我在 where 子句中有日期。
WITH
MEMBER [Amount LM] as
(
[Measures].[Amount],
ParallelPeriod (
[Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month],
1,
[Date].[Year - Quarter - Month - Date - Hierarchy].CurrentMember
)
)
SELECT
{[Amount LM], [Measures].[Amount]} ON COLUMNS,
[Measure Types].[Name].&[22] --not related to [Measures].[Amount]; Used as a measure switch in the real case but adjusted here for simplicity
-- comment out the next line to fail
* [Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month]
ON rows
FROM [Cube]
WHERE [Date].[Year Number].&[2019]
;
工作案例的结果:
Amount LM | Amount
Costs | Jan 2019 | (null) | 109600
Costs | Feb 2019 | 109600 | 218300.5
Costs | Mar 2019 | 218300.5 | 392250
Costs | Apr 2019 | 392250 | 206800
Costs | May 2019 | 206800 | 174700
Costs | Jun 2019 | 174700 | 298400
Costs | Jul 2019 | 298400 | 264550
Costs | Aug 2019 | 264550 | 424100
Costs | Sep 2019 | 424100 | 129650
Costs | Oct 2019 | 129650 | 330050
Costs | Nov 2019 | 330050 | (null)
Costs | Dec 2019 | (null) | (null)
没有
* [Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month]
part, Amount LM ist NULL
|Amount LM| Amount
Costs | (null) | 2548400.5
你的计算没有问题。要了解 Null,您需要了解
- ParallelPeriod 的工作原理
- UserHierarchy "CurrentMember" 如何工作
当你有
"[Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month]"
在你的行轴上
"[Date].[Year - Quarter - Month - Date - Hierarchy].CurrentMember"
上面的“.currentmember”表达式return是USER HIERARCHY“[Year - Quarter - Month - Date - Hierarchy]”的当前成员。 PARALLEL PERIOD 函数然后尝试查找关于 LEVEL“[Year and Month]”的表亲成员。
当您从 rows 中删除用户层次结构时,当前成员 returns 2019,它是 LEVEL "YEAR Number" 的成员,因此并行期找不到关于 LEVEL 的表亲“[Year和月]”(因为传递的当前成员高于指定的级别)。要检查用月份成员(并且行上没有日期)替换其中的年份,它将起作用。要解决此问题,您需要提供备用逻辑,以防万一传递了更高级别的成员或其他边缘情况使用下面的脚本,它将 return 100 在任何边缘情况下。
WITH
MEMBER [Amount LM] as
case when [Date].[Year - Quarter - Month - Date - Hierarchy].CurrentMember.level.name <>"Year and Month" then 100
else
(
[Measures].[Amount],
ParallelPeriod (
[Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month],
1,
[Date].[Year - Quarter - Month - Date - Hierarchy].CurrentMember
)
)
end
以下是您在 Adventure works 上遇到的问题的示例。
我添加了两列来检查 ParallelPeriod 和 .currentmember 是什么 return
WITH
MEMBER [Amount LM] as
(
[Measures].[Internet Sales Amount],
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember)
)
MEMBER [Amount LM_ParallelPeriodName] as
(
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember).name
)
MEMBER [Amount LM_CalendarCurrentmember] as
(
[Date].[Calendar].currentmember.name
)
SELECT
{[Amount LM], [Measures].[Internet Sales Amount],[Amount LM_ParallelPeriodName],[Amount LM_CalendarCurrentmember]} ON COLUMNS,
[Product].[Category].&[1] * [Date].[Calendar].[Month]
ON rows
from [Adventure Works]
WHERE [Date].[Calendar Year].&[2013]
结果
现在让我们评论
"[Date].[Calendar].[Month]"
WITH
MEMBER [Amount LM] as
(
[Measures].[Internet Sales Amount],
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember)
)
MEMBER [Amount LM_ParallelPeriodName] as
(
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember).name
)
MEMBER [Amount LM_CalendarCurrentmember] as
(
[Date].[Calendar].currentmember.name
)
SELECT
{[Amount LM], [Measures].[Internet Sales Amount],[Amount LM_ParallelPeriodName],[Amount LM_CalendarCurrentmember]} ON COLUMNS,
[Product].[Category].&[1] --* [Date].[Calendar].[Month]
ON rows
from [Adventure Works]
WHERE [Date].[Calendar Year].&[2013]
结果
注意由 ParallelPeriod 编辑的 Null return,现在让我们从 Month 中替换 Year。这使 paralellperiod 能够 return 一些有用的东西
WITH
MEMBER [Amount LM] as
(
[Measures].[Internet Sales Amount],
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember)
)
MEMBER [Amount LM_ParallelPeriodName] as
(
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember).name
)
MEMBER [Amount LM_CalendarCurrentmember] as
(
[Date].[Calendar].currentmember.name
)
SELECT
{[Amount LM], [Measures].[Internet Sales Amount],[Amount LM_ParallelPeriodName],[Amount LM_CalendarCurrentmember]} ON COLUMNS,
[Product].[Category].&[1] * [Date].[Calendar].[Month]
ON rows
from [Adventure Works]
WHERE [Date].[Month Name].[September 2013]
结果
此查询中计算的成员 [Amount LM](=amount last month)有什么问题?如果我在行上指定时间似乎有效,但如果我不指定时间则失败,即使我在 where 子句中有日期。
WITH
MEMBER [Amount LM] as
(
[Measures].[Amount],
ParallelPeriod (
[Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month],
1,
[Date].[Year - Quarter - Month - Date - Hierarchy].CurrentMember
)
)
SELECT
{[Amount LM], [Measures].[Amount]} ON COLUMNS,
[Measure Types].[Name].&[22] --not related to [Measures].[Amount]; Used as a measure switch in the real case but adjusted here for simplicity
-- comment out the next line to fail
* [Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month]
ON rows
FROM [Cube]
WHERE [Date].[Year Number].&[2019]
;
工作案例的结果:
Amount LM | Amount
Costs | Jan 2019 | (null) | 109600
Costs | Feb 2019 | 109600 | 218300.5
Costs | Mar 2019 | 218300.5 | 392250
Costs | Apr 2019 | 392250 | 206800
Costs | May 2019 | 206800 | 174700
Costs | Jun 2019 | 174700 | 298400
Costs | Jul 2019 | 298400 | 264550
Costs | Aug 2019 | 264550 | 424100
Costs | Sep 2019 | 424100 | 129650
Costs | Oct 2019 | 129650 | 330050
Costs | Nov 2019 | 330050 | (null)
Costs | Dec 2019 | (null) | (null)
没有
* [Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month]
part, Amount LM ist NULL
|Amount LM| Amount
Costs | (null) | 2548400.5
你的计算没有问题。要了解 Null,您需要了解
- ParallelPeriod 的工作原理
- UserHierarchy "CurrentMember" 如何工作
当你有
"[Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month]"
在你的行轴上
"[Date].[Year - Quarter - Month - Date - Hierarchy].CurrentMember"
上面的“.currentmember”表达式return是USER HIERARCHY“[Year - Quarter - Month - Date - Hierarchy]”的当前成员。 PARALLEL PERIOD 函数然后尝试查找关于 LEVEL“[Year and Month]”的表亲成员。
当您从 rows 中删除用户层次结构时,当前成员 returns 2019,它是 LEVEL "YEAR Number" 的成员,因此并行期找不到关于 LEVEL 的表亲“[Year和月]”(因为传递的当前成员高于指定的级别)。要检查用月份成员(并且行上没有日期)替换其中的年份,它将起作用。要解决此问题,您需要提供备用逻辑,以防万一传递了更高级别的成员或其他边缘情况使用下面的脚本,它将 return 100 在任何边缘情况下。
WITH
MEMBER [Amount LM] as
case when [Date].[Year - Quarter - Month - Date - Hierarchy].CurrentMember.level.name <>"Year and Month" then 100
else
(
[Measures].[Amount],
ParallelPeriod (
[Date].[Year - Quarter - Month - Date - Hierarchy].[Year and Month],
1,
[Date].[Year - Quarter - Month - Date - Hierarchy].CurrentMember
)
)
end
以下是您在 Adventure works 上遇到的问题的示例。 我添加了两列来检查 ParallelPeriod 和 .currentmember 是什么 return
WITH
MEMBER [Amount LM] as
(
[Measures].[Internet Sales Amount],
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember)
)
MEMBER [Amount LM_ParallelPeriodName] as
(
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember).name
)
MEMBER [Amount LM_CalendarCurrentmember] as
(
[Date].[Calendar].currentmember.name
)
SELECT
{[Amount LM], [Measures].[Internet Sales Amount],[Amount LM_ParallelPeriodName],[Amount LM_CalendarCurrentmember]} ON COLUMNS,
[Product].[Category].&[1] * [Date].[Calendar].[Month]
ON rows
from [Adventure Works]
WHERE [Date].[Calendar Year].&[2013]
结果
现在让我们评论
"[Date].[Calendar].[Month]"
WITH
MEMBER [Amount LM] as
(
[Measures].[Internet Sales Amount],
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember)
)
MEMBER [Amount LM_ParallelPeriodName] as
(
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember).name
)
MEMBER [Amount LM_CalendarCurrentmember] as
(
[Date].[Calendar].currentmember.name
)
SELECT
{[Amount LM], [Measures].[Internet Sales Amount],[Amount LM_ParallelPeriodName],[Amount LM_CalendarCurrentmember]} ON COLUMNS,
[Product].[Category].&[1] --* [Date].[Calendar].[Month]
ON rows
from [Adventure Works]
WHERE [Date].[Calendar Year].&[2013]
结果
WITH
MEMBER [Amount LM] as
(
[Measures].[Internet Sales Amount],
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember)
)
MEMBER [Amount LM_ParallelPeriodName] as
(
ParallelPeriod ([Date].[Calendar].[Month],1,[Date].[Calendar].currentmember).name
)
MEMBER [Amount LM_CalendarCurrentmember] as
(
[Date].[Calendar].currentmember.name
)
SELECT
{[Amount LM], [Measures].[Internet Sales Amount],[Amount LM_ParallelPeriodName],[Amount LM_CalendarCurrentmember]} ON COLUMNS,
[Product].[Category].&[1] * [Date].[Calendar].[Month]
ON rows
from [Adventure Works]
WHERE [Date].[Month Name].[September 2013]
结果