如何合并具有不同度量和过滤器的两个MDX查询结果?

时间:2017-03-24 10:52:30

标签: ssas mdx adomd.net

让我们首先说我是MDX的新手,我需要将两个(或更多)查询结果合并到一个支点。

查询在ROWS和COLUMNS上具有相同的尺寸,但是不同的度量和过滤器(通常是一段时间)。

这是一个例子

查询1:

SELECT
NON EMPTY {{[stores].[storecountry].[storecountry].Members}} ON COLUMNS, 
NON EMPTY {{[SalesTypes].[Description].[Description].Members}} * 
           {[Measures].[TransactionValue], [Measures].[TransQty]} ON ROWS 
FROM [Model] 
WHERE ({[dDates].[Date].[Date].&[2016-01-05T00:00:00] : [dDates].[Date].[Date].&[2016-01-12T00:00:00]})

查询1的结果:

                                    CA    US
Regular Sale    TransactionValue    761   16
Regular Sale    TransQty            8     233
Return          TransactionValue    156   4
Return          TransQty            1     45

查询2:

SELECT
NON EMPTY {{[stores].[storecountry].[storecountry].Members}} ON COLUMNS, 
NON EMPTY {{[SalesTypes].[Description].[Description].Members}} * 
           {[Measures].[DiscountPerc]} ON ROWS 
FROM [Model] 
WHERE ({[dDates].[Date].[Date].&[2015-03-12T00:00:00] : [dDates].[Date].[Date].&[2015-06-02T00:00:00]})

查询2的结果:

                                CA       US
Regular Sale    DiscountPerc    40 %     59 %
Return          DiscountPerc    32 %     43 %

合并后的预期结果

                                    CA       US
Regular Sale    TransactionValue    761      16
Regular Sale    TransQty            8        233
Regular Sale    DiscountPerc        40 %     59 %
Return          TransactionValue    156      4
Return          TransQty            1        45
Return          DiscountPerc        32 %     43 %

如果不从调用应用程序手动合并AdomdClient.CellSet,是否可以实现?

谢谢!

1 个答案:

答案 0 :(得分:1)

我使用计算成员:

with 
Member [Measures].[TransactionValueReport] as
Aggregate(
    {[dDates].[Date].[Date].&[2016-01-05T00:00:00]:[dDates].[Date].[Date].&[2016-01-12T00:00:00]},
    [Measures].[TransactionValue]
)

Member [Measures].[TransQtyReport] as
Aggregate(
    {[dDates].[Date].[Date].&[2016-01-05T00:00:00]:[dDates].[Date].[Date].&[2016-01-12T00:00:00]},
    [Measures].[TransQty]
)

Member [Measures].[DiscountPercReport] as
Aggregate(
    {[dDates].[Date].[Date].&[2015-03-12T00:00:00]:[dDates].[Date].[Date].&[2015-06-02T00:00:00]},
    [Measures].[DiscountPerc]
)

Select
Non Empty [stores].[storecountry].[storecountry].Members on 0,
Non Empty [SalesTypes].[Description].[Description].Members * {[Measures].[TransactionValueReport],[Measures].[TransQtyReport],[Measures].[DiscountPercReport]} on 1
From [Model]