Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 在MDX函数中使用计算成员作为参数_Sql Server_Ssas_Mdx - Fatal编程技术网

Sql server 在MDX函数中使用计算成员作为参数

Sql server 在MDX函数中使用计算成员作为参数,sql-server,ssas,mdx,Sql Server,Ssas,Mdx,我是MDX新手,但希望尽可能保持我的代码干净 我有一个查询,它查看今天的销售额,并使用ParallelPeriod函数将它们与LY和LY-1进行比较。它看起来像这样 With Member [Date].[SalesCalendar].[DateToday] as [Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00] SELECT {[Date].[SalesCalendar].[DateToday], Para

我是MDX新手,但希望尽可能保持我的代码干净

我有一个查询,它查看今天的销售额,并使用ParallelPeriod函数将它们与LY和LY-1进行比较。它看起来像这样

With Member [Date].[SalesCalendar].[DateToday] as [Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00]

SELECT 

    {[Date].[SalesCalendar].[DateToday],

    ParallelPeriod([Date].[SalesCalendar].[Year],1,[Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00]),

    ParallelPeriod([Date].[SalesCalendar].[Year],2,[Date].[SalesCalendar].[DateToday]}

    *  

    {[Measures].[Total Sales],[Measures].[Units],[Measures].[Sales Target]}
    ON Columns,

    [Locations].[Location PK].[Location PK]
    on Rows

From MyCube
我首先定义一个指向今天日期的成员。我想定义它一次,并在整个查询(以及我编写的其他查询)中使用它,理论上我可以在一次位置更改它,而底层查询会做出反应

我的问题是,如果我尝试在ParallelPeriod函数中使用这个计算成员,我将不会得到任何结果。通过上面的查询,我得到了第一列的结果,第一次调用ParallelPeriod(对于LY)有效,但第二次调用LY-1(使用声明的成员)失败

我猜这是因为我缺乏MDX方面的知识,所以我想我遗漏了一些基本的东西。然而,我的头撞在墙上不起作用,所以我需要一些帮助

你知道我做错了什么吗


谢谢

这无法工作,因为在计算查询时,
[Date].[SalesCalendar].[DateToday].
不会替换为
[Date].[SalesCalendar].[Date].&2012-10-26T00:00:00]

您创建了一个成员,该成员将提供与透视表单元格中的
[Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00]
相同的数值

您可以尝试以下查询:

With Member [Date].[SalesCalendar].[DateToday] as [Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00]
     Member [Measures].[name] as [Date].[SalesCalendar].CurrentMember.Name

SELECT 
    {[Measures].[name], [Measures].[Total Sales]} ON Columns,
    {[Date].[SalesCalendar].[DateToday], [Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00]} on Rows
From MyCube
总销售额
将是相同的,但不是
[Measures].[name]