简体   繁体   English

在MDX函数中将计算所得的成员用作参数

[英]Using calculated member as parameter in MDX function

I'm new to MDX but want to keep my code as clean as possible. 我是MDX的新手,但想保持我的代码尽可能整洁。

I have a query that looks at todays sales and compares them against LY and LY-1 using the ParallelPeriod function. 我有一个查询,查询今天的销售情况,并使用ParallelPeriod函数将其与LY和LY-1进行比较。 It looks something like this.. 看起来像这样。

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

I start by defining a member that points to today's date. 我首先定义一个指向今天的日期的成员。 I want to define it once and use it throughout this query (and other queries I write), the theory being I can change it in once place and the underlying query reacts. 我想一次定义它,并在整个查询(以及我编写的其他查询)中使用它,理论上讲,我可以一次更改它,并且基础查询会做出反应。

The problem I have is that if I try and use this calculated member within the ParallelPeriod function I get no results. 我遇到的问题是,如果我尝试在ParallelPeriod函数中使用此计算所得成员,则不会获得任何结果。 With the query above I get results for the first column and the first call to ParallelPeriod (for LY) works but the second call for LY-1, which uses the declared member, fails. 通过上面的查询,我得到第一列的结果,并且对ParallelPeriod的第一次调用(对于LY)有效,但是对使用已声明成员的LY-1的第二次调用失败。

I'm guessing this is down to my lack of knowledge with MDX and so I guess I am missing something fundamental. 我猜这是由于我缺乏对MDX的了解,所以我想我缺少一些基本知识。 However, banging my head against the wall isn't working so I need some help! 但是,用头撞墙是行不通的,因此我需要一些帮助!

Any ideas what I am doing wrong? 有什么想法我做错了吗?

Thanks 谢谢

This cannot work because when your query is evaluated [Date].[SalesCalendar].[DateToday] is not replaced with [Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00] . 这行不通,因为当您的查询评估为[Date].[SalesCalendar].[DateToday] ,没有替换为[Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00]

You created a member that will give the same numeric values than [Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00] in the pivot table cells. 您在透视表单元格中创建了一个成员,该成员将提供与[Date].[SalesCalendar].[Date].&[2012-10-26T00:00:00]相同的数值。

You can try this query: 您可以尝试以下查询:

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

The Total Sales will be the same but not [Measures].[name] . Total Sales将相同,但[Measures].[name]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM