我们说我有以下MDX
查询:
Select
{measures.[Dollars]} on 0,
non empty
[Divisions].[Division].[All].Children *
[Cost Centres].[Cost Centre].[All].Children
[Locations].[Locations].[All].Children
on 1
From MyCube
产生了下表:
<table><tbody><tr><th>Division</th><th> Cost Centre</th><th> Location</th><th> Dollars</th></tr><tr><td>AA</td><td>1</td><td>X</td><td>$30.00 </td></tr><tr><td>AA</td><td>1</td><td>X</td><td>$12.32 </td></tr><tr><td>AA</td><td>1</td><td>X</td><td>$124.32 </td></tr><tr><td>AA</td><td>1</td><td>Z</td><td>$64.24 </td></tr><tr><td>BB</td><td>1</td><td>Z</td><td>$63.13 </td></tr><tr><td>BB</td><td>1</td><td>Z</td><td>$84.23 </td></tr><tr><td>BB</td><td>2</td><td>Z</td><td>$254.37 </td></tr><tr><td>BB</td><td>2</td><td>Y</td><td>$27.23 </td></tr><tr><td>CC</td><td>2</td><td>Z</td><td>$12.01 </td></tr><tr><td>CC</td><td>2</td><td>Y</td><td>$12.42 </td></tr><tr><td>CC</td><td>2</td><td>Y</td><td>$53.26 </td></tr><tr><td>CC</td><td>1</td><td>Y</td><td>$76.26 </td></tr><tr><td>CC</td><td>1</td><td>Z</td><td>$63.74 </td></tr><tr><td>CC</td><td>1</td><td>Z</td><td>$2.74 </td></tr></tbody></table>
&#13;
我希望做的是在[成本中心]。[成本中心]和[地点]。[地点]层次结构中创建一个特定值的联合集合到一个集合中并使用该新集合我对列中的MDX查询。
使用上面的表和查询,我有以下条件来确定集合中的值(让我们调用新集合&#39; NewSet&#39;):
When Cost Centre = 1 and Location = X Then "CustomType1"
When Cost Centre = 1 and Location = Y Then "CustomType2"
When Cost Centre = 1 and Location = Z Then "CustomType3"
When Cost Centre = 2 and Location = Y Then "CustomType4"
When Cost Centre = 2 and Location = Z Then "CustomType5"
Else "Default"
然后,如果我要执行新查询:
with
set NewSet as "Some Unknown Magic Here"
Select {measures.[Dollars]} on 0,
non empty
[Divisions].[Division].[All].Children *
{NewSet}
on 1
From MyCube
我最终会得到以下结果:
<table><tbody><tr><th>Division</th><th> NewSet</th><th>Dollars</th></tr><tr><td>AA</td><td>CustomType1 </td><td>$166.64 </td></tr><tr><td>AA</td><td>CustomType3 </td><td>$64.24 </td></tr><tr><td>BB</td><td>CustomType3 </td><td>$147.36 </td></tr><tr><td>BB</td><td>CustomType4</td><td>$27.23 </td></tr><tr><td>BB</td><td>CustomType5</td><td>$254.37 </td></tr><tr><td>CC</td><td>CustomType2</td><td>$76.26 </td></tr><tr><td>CC</td><td>CustomType3</td><td>$66.48 </td></tr><tr><td>CC</td><td>CustomType4</td><td>$65.68 </td></tr><tr><td>CC</td><td>CustomType5</td><td>$12.01 </td></tr></tbody></table>
&#13;
答案 0 :(得分:0)
您只需拥有一组您感兴趣的每个层次结构的成员元组:
SELECT
{measures.[Dollars]} ON 0
,NON EMPTY
[Divisions].[Division].[All].Children*
{
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[x]),
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[y]),
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[z]),
([Cost Centres].[Cost Centre].[2], [Locations].[Locations].[y]),
([Cost Centres].[Cost Centre].[2], [Locations].[Locations].[z])
}
ON 1
FROM MyCube;
或者这可以像您的问题一样放在WITH
子句中:
WITH SET [BLAH] AS
{
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[x]),
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[y]),
([Cost Centres].[Cost Centre].[1], [Locations].[Locations].[z]),
([Cost Centres].[Cost Centre].[2], [Locations].[Locations].[y]),
([Cost Centres].[Cost Centre].[2], [Locations].[Locations].[z])
}
SELECT
{measures.[Dollars]} ON 0
,NON EMPTY
[Divisions].[Division].[All].Children*
[BLAH]
ON 1
FROM MyCube;