MDX组合查询

时间:2018-08-05 20:34:23

标签: sql-server mdx

我是MDX的新手,正在尝试将2个独立的查询合并为以下格式:

|产品名称| Quantity Madison_Chicago | Quantity Chicago_Madison |

我有两个查询,分别为下面列出的数量创建每个条件:

------Query #1------
WITH
   MEMBER measures.Quantity_Madison_Chicago as 'COALESCEEMPTY( [Measures]. 
   [Quantity - Tb Transactions], 0)' 
SELECT {
    measures.Quantity_Madison_Chicago
} ON COLUMNS,
  {(
    [Tb Product].[Name].[Name].ALLMEMBERS
  )} ON ROWS
FROM (
  SELECT ({
    [Tb Consumer].[City].&[Chicago]
  }) ON COLUMNS
FROM (  
  SELECT ({ 
    [Tb Supplier].[City].&[Madison]
  }) ON COLUMNS
FROM [DS715]))

------Query #2------
WITH
   MEMBER measures.Quantity_Chicago_Madison as 'COALESCEEMPTY( [Measures]. 
   [Quantity - Tb Transactions], 0)'
SELECT {
   measures.Quantity_Chicago_Madison
} ON COLUMNS,
{(
    [Tb Product].[Name].[Name].ALLMEMBERS
)} ON ROWS
FROM (
   SELECT ({
     [Tb Consumer].[City].&[Madison]
}) ON COLUMNS
FROM (
   SELECT ({
     [Tb Supplier].[City].&[Chicago]
}) ON COLUMNS
FROM [DS715]))

任何帮助将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用两个计算所得的成员来完成此操作:

WITH  
MEMBER measures.Quantity_Madison_Chicago 
  CASE WHEN
      [Tb Consumer].[City].currentMember=[Tb Consumer].[City].&[Chicago]
         AND
      [Tb Supplier].[City].currentMember=[Tb Supplier].[City].&[Madison]
THEN COALESCEEMPTY( [Measures]. 
   [Quantity - Tb Transactions], 0)
ELSE 0
END

MEMBER measures.Quantity_Chicago_Madison AS
  CASE WHEN
      [Tb Consumer].[City].currentMember=[Tb Consumer].[City].&[Madison]
         AND
      [Tb Supplier].[City].currentMember=[Tb Supplier].[City].&[Chicago]
THEN COALESCEEMPTY( [Measures]. 
   [Quantity - Tb Transactions], 0)
ELSE 0
END


SELECT {
   measures.Quantity_Chicago_Madison , measures.Quantity_Madison_Chicago 
} ON COLUMNS,
{  [Tb Product].[Name].[Name].ALLMEMBERS } ON ROWS
FROM [DS715]

我认为您无需为了选择而在供应商/消费者城市上切块即可工作,但是我目前没有SSAS可以尝试。如果这样不起作用,请像使用2个计算所得的成员一样进行选择,然后在消费者和供应商维度子选择中添加城市