我刚拿到一个关于 SSAS 多维数据集和多维表达式的项目交接。有一个用Visual Studio写的计算:
(StrToMember(
"[DIM Time_V3].[Year - Week - Date].[Month].&["+
MID(MemberToStr([DIM Time_V3].[Year - Month - Day].CurrentMember)
,44,11)+"T00:00:00]"),[Plan Revenue])
此公式因未知原因无效(Excel 数据透视表显示#VALUE!在此公式下)。
我把上面的公式在SSMS中转换成MDX查询:
SELECT
[Measures].[Plan Revenue] ON COLUMNS,
StrToMember(
"[DIM Time_V3].[Year - Week - Date].[Month].&["
+ MID(MemberToStr([DIM Time_V3].[Year - Month - Day].CurrentMember),44,11)
+ "T00:00:00]"
) ON ROWS
FROM [FR_ACCOUNTING 3]
出现错误提示“'T00:00:00' 字符串无法转换为日期类型”。然后我尝试了以下脚本:
SELECT [Measures].[Plan Revenue] ON COLUMNS,
[DIM Time_V3].[Year - Week - Date].[Month] ON ROWS
FROM [FR_ACCOUNTING 3]
这里是上述查询结果的随机成员:
Caption Manufacturing Period 1, 2023
Name [DIM TIME_V3].[Year - Week - Date].[Month].&[2023-01-03T00:00:00]
UniqueName [DIM TIME_V3].[Year - Week - Date].[Month].&[2023-01-03T00:00:00]
Description
LevelName [DIM TIME_V3].[Year - Week - Date].[Month]
LevelDepth 3
DrilledDown False
ParentSameAsPrevious False
ChildCount 4
SELECT [Measures].[Plan Revenue] ON COLUMNS,
[DIM Time_V3].[Year - Month - Day].[Manufacturing Month] ON ROWS
FROM [FR_ACCOUNTING 3]
这里是上述查询结果的随机成员:
Caption Manufacturing Period 1, 2023
Name [DIM TIME_V3].[Year - Month - Day].[Manufacturing Month].&[2023-01-03T00:00:00]
UniqueName [DIM TIME_V3].[Year - Month - Day].[Manufacturing Month].&[2023-01-03T00:00:00]
Description
LevelName [DIM TIME_V3].[Year - Month - Day].[Manufacturing Month]
LevelDepth 2
DrilledDown False
ParentSameAsPrevious False
ChildCount 28
我还尝试了以下代码,看看硬编码而不是 MID 函数是否可以返回一些东西:
SELECT
[Measures].[Plan Revenue] ON COLUMNS,
StrToMember(
"[DIM Time_V3].[Year - Week - Date].[Month].&["
+ "2022-01-03"
+ "T00:00:00]"
) ON ROWS
FROM [FR_ACCOUNTING 3]
--Check if MID function works for manufacturing calendar
SELECT
[Measures].[Plan Revenue] ON COLUMNS,
StrToMember(
"[DIM Time_V3].[Year - Week - Date].[Month].&["
+ MID(MemberToStr([DIM Time_V3].[Year - Month - Day].CurrentMember),44,11)
+ "]"
) ON ROWS
FROM [FR_ACCOUNTING 3]
结果说“The '' string cannot be converted to the date type”。 我很好奇 MID 函数如何工作以及我们如何提取成员的子字符串。非常感谢解决我的问题。