MDX - Как «суммировать» отфильтрованный набор результатов - PullRequest
0 голосов
/ 07 февраля 2020

Я изо всех сил пытаюсь определить правильный синтаксис запроса MDX, чтобы вернуть ожидаемый набор результатов после перемещения фильтров для поддержки расширенной вложенной фильтрации.

Запрос ниже - это то, что генерируется сегодня, и на скриншоте показаны результаты. Есть ли у кого-нибудь понимание того, как получить необходимые результаты, как описано на скриншоте на основе запроса ниже.

Примечание. Я считаю, что фильтры должны оставаться на месте, чтобы поддерживать вложенные сложные фильтры. т.е. ((A = 1 ИЛИ B <1) И (A> 1 ИЛИ C = 2)) || (B = 3 И C = 4)

  WITH
  SET AllRowsSet AS
    {
      Filter
      (
        NonEmpty
        (
            called_cities.[called_city].Children*
            called_countries.[called_country_name].Children*
            billing_months.[billing_month].Children*
            sources_pivot_v1.[source_name_l1].Children*
            products_pivot.[product_name_l1].Children*
            products_pivot.[product_name_l2].Children
            ,{
                [Measures].[actual_duration]
                ,[Measures].[amount]
            }
        )
       ,
        billing_months.[billing_month].CurrentMember.Member_Caption = '201805'
        AND products_pivot.[product_name_l1].CurrentMember.Member_Caption = 'Usage'
        AND products_pivot.[product_name_l2].CurrentMember.Member_Caption = 'LD International'
        AND called_countries.[called_country_name].CurrentMember.Member_Caption <> 'TEST_NULL'
        AND (
            sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption = 'Company for Joint'
            OR sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption = 'Cisco Call Manager'
        )
      )
    }
  MEMBER [Measures].totalrows AS AllRowsSet.Count
  MEMBER [Measures].[called_city] AS called_cities.[called_city].CurrentMember.Member_Caption
  MEMBER [Measures].[called_country_name] AS called_countries.[called_country_name].CurrentMember.Member_Caption
  MEMBER [Measures].[billing_month] AS billing_months.[billing_month].CurrentMember.Member_Caption
  MEMBER [Measures].[source_name_l1] AS sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption
  MEMBER [Measures].[product_name_l1] AS products_pivot.[product_name_l1].CurrentMember.Member_Caption
  MEMBER [Measures].[product_name_l2] AS products_pivot.[product_name_l2].CurrentMember.Member_Caption

SELECT
  {
    [Measures].[actual_duration]
   ,[Measures].[amount]
   ,[Measures].totalrows
   ,[Measures].[called_city]
   ,[Measures].[called_country_name]
   ,[Measures].[billing_month]
   ,[Measures].[source_name_l1]
   ,[Measures].[product_name_l1]
   ,[Measures].[product_name_l2]
  } ON COLUMNS
 ,SubSet
  (
    Order
    (
      Filter
      (
        NonEmpty
        (
            called_cities.[called_city].Children*
            called_countries.[called_country_name].Children*
            billing_months.[billing_month].Children*
            sources_pivot_v1.[source_name_l1].Children*
            products_pivot.[product_name_l1].Children*
            products_pivot.[product_name_l2].Children
         ,{
            [Measures].[actual_duration]
           ,[Measures].[amount]
          }
        )
       ,
        billing_months.[billing_month].CurrentMember.Member_Caption = '201805'
        AND products_pivot.[product_name_l1].CurrentMember.Member_Caption = 'Usage'
        AND products_pivot.[product_name_l2].CurrentMember.Member_Caption = 'LD International'
        AND called_countries.[called_country_name].CurrentMember.Member_Caption <> 'TEST_NULL'
        AND (
            sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption = 'Company for Joint'
            OR sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption = 'Cisco Call Manager'
        )
      )
     ,[Measures].[amount]
     ,BDESC
    )
   ,0
   ,250
  ) ON ROWS
FROM
(
  SELECT {billing_months.[v1_disabled].[v1_disabled].&[0]} ON 0 FROM calls
);

enter image description here

1 Ответ

0 голосов
/ 08 февраля 2020

Для агрегирования вы можете: 1. Переместить набор ON ROWS в предложение WITH 2. Обернуть его в Aggregate 3. Вам нужно будет найти «лишнее» измерение в вашем кубе, которое не используется в этом запросе, чтобы создать этот новый пользовательский член:

WITH
  SET AllRowsSet AS
    {
      Filter
      (
        NonEmpty
        (
            called_cities.[called_city].Children*
            called_countries.[called_country_name].Children*
            billing_months.[billing_month].Children*
            sources_pivot_v1.[source_name_l1].Children*
            products_pivot.[product_name_l1].Children*
            products_pivot.[product_name_l2].Children
            ,{
                [Measures].[actual_duration]
                ,[Measures].[amount]
            }
        )
       ,
        billing_months.[billing_month].CurrentMember.Member_Caption = '201805'
        AND products_pivot.[product_name_l1].CurrentMember.Member_Caption = 'Usage'
        AND products_pivot.[product_name_l2].CurrentMember.Member_Caption = 'LD International'
        AND called_countries.[called_country_name].CurrentMember.Member_Caption <> 'TEST_NULL'
        AND (
            sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption = 'Company for Joint'
            OR sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption = 'Cisco Call Manager'
        )
      )
    }
  MEMBER [Measures].totalrows AS AllRowsSet.Count
  MEMBER [Measures].[called_city] AS called_cities.[called_city].CurrentMember.Member_Caption
  MEMBER [Measures].[called_country_name] AS called_countries.[called_country_name].CurrentMember.Member_Caption
  MEMBER [Measures].[billing_month] AS billing_months.[billing_month].CurrentMember.Member_Caption
  MEMBER [Measures].[source_name_l1] AS sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption
  MEMBER [Measures].[product_name_l1] AS products_pivot.[product_name_l1].CurrentMember.Member_Caption
  MEMBER [Measures].[product_name_l2] AS products_pivot.[product_name_l2].CurrentMember.Member_Caption

MEMBER [SpareDimension].[SpareHierarchy].[myAggregation] AS   //<< REPLACE <[SpareDimension].[SpareHierarchy]> WITH A VALID DIMENSION/HIERARCHY IN YOUR CUBE THAT IS NOT BEING USED IN THE SCRIPT
Aggregate(
SubSet
  (
    Order
    (
      Filter
      (
        NonEmpty
        (
            called_cities.[called_city].Children*
            called_countries.[called_country_name].Children*
            billing_months.[billing_month].Children*
            sources_pivot_v1.[source_name_l1].Children*
            products_pivot.[product_name_l1].Children*
            products_pivot.[product_name_l2].Children
         ,{
            [Measures].[actual_duration]
           ,[Measures].[amount]
          }
        )
       ,
        billing_months.[billing_month].CurrentMember.Member_Caption = '201805'
        AND products_pivot.[product_name_l1].CurrentMember.Member_Caption = 'Usage'
        AND products_pivot.[product_name_l2].CurrentMember.Member_Caption = 'LD International'
        AND called_countries.[called_country_name].CurrentMember.Member_Caption <> 'TEST_NULL'
        AND (
            sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption = 'Company for Joint'
            OR sources_pivot_v1.[source_name_l1].CurrentMember.Member_Caption = 'Cisco Call Manager'
        )
      )
     ,[Measures].[amount]
     ,BDESC
    )
   ,0
   ,250
  )
)
SELECT
  {
    [Measures].[actual_duration]
  } ON COLUMNS
 ,[SpareDimension].[SpareHierarchy].[myAggregation] ON ROWS
FROM
(
  SELECT {billing_months.[v1_disabled].[v1_disabled].&[0]} ON 0 FROM calls
);
...