2

我试图找出哪个州的经销商销售额最高的年份。我正在使用 Adventure Works DW 2008 R2 数据库。

这是我得到的查询 -

SELECT { [Reseller Sales Amount] } ON COLUMNS,
{
  Generate (
    [Geography].[Geography].[Country].Members,
    TopCount (
      Order (
        Descendants ( 
           [Geography].[Geography].CurrentMember
         , [Geography].[Geography].[State-Province] 
        ) 
       *[Date].[Calendar].[Calendar Year].Members,
        [Reseller Sales Amount],
        DESC
      ),
      1
    )
  )
} ON ROWS
FROM [Adventure Works]

对于法国,它显示 (null) 作为结果集。还有为什么它没有列出所有的州-省而只列出其中的几个?是否也可以将国家与结果放在一起。当我尝试另一个交叉连接时,我收到错误说地理层次结构已经存在。

4

2 回答 2

1

要摆脱 null 您可以使用BDESC而不是DESC. 额外的B意味着所有自然层次顺序都将被打破

SELECT { [Reseller Sales Amount] } ON COLUMNS,
{
  Generate (
    [Geography].[Geography].[Country].Members,
    TopCount (
      Order (
        Descendants ( 
           [Geography].[Geography].CurrentMember
         , [Geography].[Geography].[State-Province] 
        ) 
       *[Date].[Calendar].[Calendar Year].Members,
        [Reseller Sales Amount],
        BDESC //<<< 
      ),
      1
    )
  )
} ON ROWS
FROM [Adventure Works];

要添加国家/地区并避免您看到的错误,请使用未使用的属性层次结构,而不是您在 1 轴上已有[Geography].[Country]的用户层次结构:[Geography].[Geography]

SELECT 
  {[Reseller Sales Amount]} ON COLUMNS
 ,{
    Generate
    (
      [Geography].[Geography].[Country].MEMBERS
     ,TopCount
      (
        Order
        (
            [Geography].[Country].[Country]*
            Descendants
            (
              [Geography].[Geography].CurrentMember
             ,[Geography].[Geography].[State-Province]
            )*
            [Date].[Calendar].[Calendar Year].MEMBERS
         ,[Reseller Sales Amount]
         ,bDESC
        )
       ,1
      )
    )
  } ON ROWS
FROM [Adventure Works];

结果如下:

在此处输入图像描述

于 2016-08-10T08:34:41.260 回答
0

我们将在层次上探索 TOP-filters 的通用选项实现。

可以为每个级别设置 TOP 规则。

它用于详细分析数据(展开、向下钻取)。

聚合是基于 TOP 形成的。

关卡上的 TOP 过滤器

只要数据在最数据透视表中排序,设置排序顺序就可以了。

SELECT
  { [Measures].[Reseller Sales Amount] }
  DIMENSION PROPERTIES PARENT_UNIQUE_NAME , HIERARCHY_UNIQUE_NAME , CUSTOM_ROLLUP , UNARY_OPERATOR , KEY0 ON 0
, ORDER
  ( HIERARCHIZE
    ( HIERARCHIZE ( [Geography].[Geography].Levels ( 0 ).Members )
    )
  , ([Measures].[Reseller Sales Amount])
  , BDESC
  )
  DIMENSION PROPERTIES PARENT_UNIQUE_NAME , HIERARCHY_UNIQUE_NAME , CUSTOM_ROLLUP , UNARY_OPERATOR , KEY0 ON 1
FROM
( SELECT
    { Generate
      ( [Geography].[Geography].Levels ( 3 ).Members
      , TopCount
        ( Filter
          ( [Geography].[Geography].CurrentMember.Children
          , NOT IsEmpty ( [Measures].[Reseller Sales Amount] )
          )
        , 3
        , [Measures].[Reseller Sales Amount]
        )
      )
    } ON COLUMNS
  FROM
  ( SELECT
      { Generate
        ( [Geography].[Geography].Levels ( 2 ).Members
        , TopCount
          ( Filter
            ( [Geography].[Geography].CurrentMember.Children
            , NOT IsEmpty ( [Measures].[Reseller Sales Amount] )
            )
          , 3
          , [Measures].[Reseller Sales Amount]
          )
        )
      } ON COLUMNS
    FROM
    ( SELECT
        { Generate
          ( [Geography].[Geography].Levels ( 1 ).Members
          , TopCount
            ( Filter
              ( [Geography].[Geography].CurrentMember.Children
              , NOT IsEmpty ( [Measures].[Reseller Sales Amount] )
              )
            , 3
            , [Measures].[Reseller Sales Amount]
            )
          )
        } ON COLUMNS
      FROM
      ( SELECT
          { Generate
            ( [Geography].[Geography].Levels ( 0 ).Members
            , TopCount
              ( Filter
                ( [Geography].[Geography].CurrentMember.Children
                , NOT IsEmpty ( [Measures].[Reseller Sales Amount] )
                )
              , 3
              , [Measures].[Reseller Sales Amount]
              )
            )
          } ON COLUMNS
        FROM
        ( SELECT
            { [Geography].[Geography].Levels ( 0 ).Members } ON COLUMNS
          FROM [Adventure Works]
        )
      )
    )
  )
)
CELL PROPERTIES BACK_COLOR , CELL_ORDINAL , FORE_COLOR , FONT_NAME , FONT_SIZE , FONT_FLAGS , FORMAT_STRING , VALUE , FORMATTED_VALUE , UPDATEABLE , ACTION_TYPE
于 2016-08-11T12:41:48.563 回答