我想知道是否有更好的方法来编写像这样的计算成员:
try:
...
except ValueError:
...
except TypeError:
...
答案 0 :(得分:2)
这是tuple
- 这是查找多维数据集一部分的一种非常有效的方法:
(
[Measures].[Number of accounts]
,[Account Status].[Account Status].&[Anonymous]
,[Account Status].[Account Status].&[Closed]
,[Account Status].[Account Status].&[Closed due to Fraud]
,[Account Status].[Account Status].&[To be closed]
,[Account Status].[Account Status].&[<unknown>]
)
...但它必须是多维数据集中的特定点 - 但您已包含来自同一层次结构[Account Status].[Account Status]
的多个成员,因此这不是您的多维数据集中的单个点,因此它将因此错误。
以下是有效元组的示例:
WITH
MEMBER [exampleTuple] AS
(
[Measures].[Internet Sales Amount]
,[Date].[Calendar Year].&[2007]
)
SELECT
[exampleTuple] ON 0
,{
[Product].[Category].[Bikes]
,[Product].[Category].[Clothing]
} ON 1
FROM [Adventure Works];
所以这给了互联网销售但仅限于2007年:
如果我做了你已经完成的事情,并且将年级层次结构中的另一个成员添加到元组中,那么它会让我感到困惑,因为我不确定我所指的那个多维数据集 - 2006年或2007年!
WITH
MEMBER [exampleTuple] AS
(
[Measures].[Internet Sales Amount]
,[Date].[Calendar Year].&[2007]
,[Date].[Calendar Year].&[2006]
)
SELECT
[exampleTuple] ON 0
,{
[Product].[Category].[Bikes]
,[Product].[Category].[Clothing]
} ON 1
FROM [Adventure Works];
给出:
双击单词#Error告诉我们异常:
正是我们所期望的例外。
解决此异常的方法是将来自同一层次结构的成员预聚合到单个成员中,以便处理器确切地知道要转到多维数据集空间的哪个部分:
WITH
MEMBER [Date].[Calendar Year].[All].[2006+2007] AS
Aggregate({[Date].[Calendar Year].&[2007],[Date].[Calendar Year].&[2006]})
MEMBER [exampleTuple] AS
(
[Measures].[Internet Sales Amount]
,[Date].[Calendar Year].[All].[2006+2007]
)
SELECT
[exampleTuple] ON 0
,{
[Product].[Category].[Bikes]
,[Product].[Category].[Clothing]
} ON 1
FROM [Adventure Works];
现在我们得到了我们想要的东西:
然后我们可以使用这个初始聚合来做任何我们想做的事情 - 你提到排除一些成员 - 这是可能的:
WITH
MEMBER [Date].[Calendar Year].[All].[2006+2007] AS
Aggregate
(
Except
(
[Date].[Calendar Year].[Calendar Year].MEMBERS
,{
[Date].[Calendar Year].&[2007]
,[Date].[Calendar Year].&[2006]
}
)
)
MEMBER [exampleTuple] AS
(
[Measures].[Internet Sales Amount]
,[Date].[Calendar Year].[All].[2006+2007]
)
SELECT
[exampleTuple] ON 0
,{
[Product].[Category].[Bikes]
,[Product].[Category].[Clothing]
} ON 1
FROM [Adventure Works];
答案 1 :(得分:0)
您的意思是创建计算度量或计算维度成员吗?
您是否可以使用EXCEPT或否定语法?
像
这样的东西(Measures.Number of accounts,{Status A,Status B}
除外或用减号代替EXCept一词。