MDX:组合不同标准的输出



我是MDX查询的新手,并且在SSA中工作。我有两个可以正常工作的查询,但是我希望它们的输出合并到一个结果中。这两个查询在其位置选择的城市中有所不同,但它们都来自相同的立方体并使用相同的措施。

A_TO_B :供应商City A到消费城市B

SELECT { [Measures].[Quantity - Transactions] } ON COLUMNS,
       { [Tb Product].[Name].[Name].ALLMEMBERS } ON ROWS
FROM [Cube]
WHERE ([Tb Supplier].[City].&[A],
       [Tb Consumer].[City].&[B])

b_to_a :供应商城市B到消费城市A

SELECT { [Measures].[Quantity - Transactions] } ON COLUMNS,
       { [Tb Product].[Name].[Name].ALLMEMBERS } ON ROWS
FROM [Cube]
WHERE ([Tb Supplier].[City].&[B],
       [Tb Consumer].[City].&[A])

是否有这样的方法可以通过产品并排生产这些查询?在SQL中,我会使用完整的外部连接,但我无法弄清MDX中的同等连接。

||A_TO_B |B_TO_A ||producta |10 |2 ||productb |100 |0 ||Productc |0 |99 |

只需将您的语句移动到列:

Select
{[Measures].[Quantity - Transactions]} *
{
    ([Tb Supplier].[City].&[B], [Tb Consumer].[City].&[A]),
    ([Tb Supplier].[City].&[A], [Tb Consumer].[City].&[B])
} on 0,
{[Tb Product].[Name].[Name].AllMembers} on 1
From [Cube]

您可以创建计算的成员以团结两个元组:

With 
Member [Tb Supplier].[City].[B2A] as
Aggregate([Tb Supplier].[City].&[B], [Tb Consumer].[City].&[A])
Member [Tb Supplier].[City].[A2B] as
Aggregate([Tb Supplier].[City].&[A], [Tb Consumer].[City].&[B])
Select 
    {[Tb Supplier].[City].[A2B],[Tb Supplier].[City].[B2A]} on 0
From [Cube]
Where ([Measures].[Quantity - Transactions])

我测试了此脚本,并引发了例外:

SELECT 
    {[Measures].[Internet Sales Amount]}
  * 
    {
      {[Geography].[Geography].[Country].&[United States] * [Product].[Category].&[1]}
     ,{[Geography].[Geography].[Country].&[France] * [Product].[Category].&[3]}
    } ON 0
 ,{[Date].[Calendar].[Date].&[20070801]} ON 1
FROM [Adventure Works];

此消息:

查询(5,7(该功能期望1个元组集表达式 争论。使用字符串或数字表达式。

这是因为您需要专门制作交叉加入的任何一侧 - 没有额外的括号,它不知道这一点并抛出例外。

所以这是脚本的"完美"版本:

SELECT 
    {[Measures].[Internet Sales Amount]}
  * 
    {
      {[Geography].[Geography].[Country].&[United States]} * {[Product].[Category].&[1]}
     ,{[Geography].[Geography].[Country].&[France]} * {[Product].[Category].&[3]}
    } ON 0
 ,{[Date].[Calendar].[Date].&[20070801]} ON 1
FROM [Adventure Works];

我宁愿将措施移至Where子句,还可以摆脱一些冗余牙套:

SELECT 
  {
      {[Geography].[Geography].[Country].&[United States]}
    * 
      {[Product].[Category].&[1]}
   ,
      {[Geography].[Geography].[Country].&[France]}
    * 
      {[Product].[Category].&[3]}
  } ON 0
 ,[Date].[Calendar].[Date].&[20070801] ON 1
FROM [Adventure Works]
WHERE 
  [Measures].[Internet Sales Amount];

翻译成您的立方体:

SELECT 
  {
    {[Tb Supplier].[City].&[B]} * {[Tb Consumer].[City].&[A]}
   ,
    {[Tb Supplier].[City].&[A]} * {[Tb Consumer].[City].&[B]}
  } ON 0
 ,[Tb Product].[Name].[Name].ALLMEMBERS ON 1
FROM [Cube]
WHERE 
  [Measures].[Quantity - Transactions];

在其他建立上构建,这是输出中用零替换为零的一个。

With 
Member [Tb Supplier].[City].[B2A] as
Aggregate([Tb Supplier].[City].&[B], [Tb Consumer].[City].&[A])
Member [Tb Supplier].[City].[A2B] as
Aggregate([Tb Supplier].[City].&[A], [Tb Consumer].[City].&[B])
Member [Measures].[Quantity_Transactions] as
    Iif( IsEmpty( [Measures].[Quantity - Transactions] ), 
    0, 
    [Measures].[Quantity - Transactions] )
SELECT 
    { [Measures].[Quantity_Transactions] } *
    { [Tb Supplier].[City].[B2A], 
      [Tb Supplier].[City].[A2B] } on COLUMNS
    , [Tb Product].[Name].[Name].ALLMEMBERS ON ROWS
FROM [Cube]

最新更新