简体   繁体   English

MDX YTD 计算度量

[英]MDX YTD calculated measure

I'm still new to MDX and I'm trying to get some basic functions to work in my SSAS cube.我还是 MDX 的新手,我正在尝试让一些基本函数在我的 SSAS 多维数据集中工作。 Can you guys point out what I'm doing wrong here?你们能指出我在这里做错了什么吗? I've added a calculated measure to my cube with the following code:我使用以下代码向我的多维数据集添加了一个计算度量:

CREATE MEMBER CURRENTCUBE.[Measures].[Amount YTD]
AS
  AGGREGATE(
    YTD([OrderDate].[Calendar].CurrentMember)
   ,[Measures].[Amount]),
VISIBLE = 1, ASSOCIATED_MEASURE_GROUP = 'MyMeasureGroup';

After that I'm trying to get some data going...在那之后,我正在尝试获取一些数据...

SELECT 
NON EMPTY
{
  [Measures].[Amount]
, [Measures].[Amount YTD]
} ON COLUMNS,
NON EMPTY
{
  [OrderDate].[Month].ALLMEMBERS *
  [Product].[Product Group].ALLMEMBERS 
} ON ROWS
FROM (SELECT ([OrderDate].[Year].&[2014-01-01T00:00:00]:
              [OrderDate].[Year].&[2015-01-01T00:00:00]) ON COLUMNS
FROM [SalesOrderIntake])

This is the output I'm getting:这是我得到的输出:

查询结果

I'm not seeing any errors in my Output messages, which makes it difficult for me to figure out what is acting up.我在输出消息中没有看到任何错误,这让我很难弄清楚发生了什么。 Hoping you guys can help me out on this one.希望大家能帮我解决这个问题。

FYI: the actual select is just for testing purposes.仅供参考:实际选择仅用于测试目的。 I just want to get that YTD running.我只是想让 YTD 运行。 I've tried several things and it always comes out empty, so I was hoping to get some actual errors if I would query it directly in SSMS instead of using a BI tool.我已经尝试了几件事,但结果总是空的,所以如果我直接在 SSMS 中查询而不是使用 BI 工具,我希望得到一些实际的错误。 Also, the OrderDate dimension is a generated Time dimension which was provided to me by VS.此外,OrderDate 维度是由 VS 提供给我的生成的时间维度。

In your query you're using what looks like an attribute hierarchy:在您的查询中,您使用的是属性层次结构:

[OrderDate].[Month].ALLMEMBERS

Whereas the measure uses the user hierarchy:而度量使用用户层次结构:

[OrderDate].[Calendar]

If you use Calendar in your script does it work ok?如果您在脚本中使用 Calendar 是否可以正常工作?

#Error usually crops up when there are run time errors in MDX code. #Error通常在MDX代码中出现运行时错误时出现。 I could think of one scenario where the error might crop up.我可以想到一种可能会出现错误的场景。 You are using [OrderDate].[Calendar].CurrentMember in the calculated member.您正在计算成员中使用[OrderDate].[Calendar].CurrentMember But if instead of one, there are multiple members from this hierarchy in scope, it will throw an error.但是,如果范围内有多个来自此层次结构的成员而不是一个,则会引发错误。

The below is a scenario from Adventure Works.下面是 Adventure Works 的一个场景。

with member abc as 
sum(YTD([Date].[Calendar].currentmember), [Measures].[Internet Sales Amount])

select abc on 0
from [Adventure Works]
where {[Date].[Calendar].[Date].&[20060115], [Date].[Calendar].[Date].&[20060315]} 

在此处输入图片说明

PS Thanks to @whytheq for teaching me this trick of checking this error by double clicking the cell :) Cheers. PS 感谢@whytheq 教我通过双击单元格来检查此错误的技巧:) 干杯。

I know, its an old post, but in the interest of posterity..我知道,这是一个旧帖子,但为了后代的利益..

The correct approach is :正确的做法是:

Aggregate
(
    PeriodsToDate
    (
        [OrderDate].[Calendar].[Fiscal Year]
        ,[OrderDate].[Calendar].CurrentMember
    )
    ,[Measures].[Amount]
)

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

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