获得每个食品子类别的前5个品牌

问题描述 投票:0回答:2

我想将类别食品的每个子类别的前5个销售品牌与使用foodmart数据库的mdx查询中的年收入进行比较。

更具体地说,我们有一个称为产品的维度,其中包含产品类别和产品的品牌名称。产品类别可能包含许多子类别。例如:

{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Blue Medal].[Blue Medal Egg Substitute]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Blue Medal].[Blue Medal Large Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Blue Medal].[Blue Medal Large Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Blue Medal].[Blue Medal Small Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Blue Medal].[Blue Medal Small Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Giant]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Giant].[Giant Egg Substitute]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Giant].[Giant Large Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Giant].[Giant Large Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Giant].[Giant Small Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Giant].[Giant Small Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Jumbo]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Jumbo].[Jumbo Egg Substitute]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Jumbo].[Jumbo Large Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Jumbo].[Jumbo Large Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Jumbo].[Jumbo Small Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Jumbo].[Jumbo Small Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[National]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[National].[National Egg Substitute]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[National].[National Large Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[National].[National Large Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[National].[National Small Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[National].[National Small Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Urban]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Urban].[Urban Egg Substitute]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Urban].[Urban Large Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Urban].[Urban Large Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Urban].[Urban Small Brown Eggs]}
{[Product].[All Products].[Food].[Eggs].[Eggs].[Eggs].[Urban].[Urban Small Eggs]}

在上面的例子中,我们可以看到子类别包含许多包含品牌的子类别。

最终目的是表明,对于子类别,年收入<10.000的人的前5个品牌是{列表}。我们希望使用度量单位销售的每个子类别的食品。

输出结果应该是:

salary   |Eggs                              |Meat
          Brand1|Brand2|Brand3|Brand4|Brand5|Brand1|Brand2|Brand3|Brand4|Brand5
&lt 10.000k |Name1 |Name2 |Name3 |Name4 |Name5 |Name1 |Name2 |Name3 |Name4 |Name5
&gt 10.000k |Name1 |Name2 |Name3 |Name4 |Name5 |Name1 |Name2 |Name3 |Name4 |Name5

任何帮助将非常感激。

grouping mdx ranking
2个回答
0
投票

您需要根据排名过滤数据。看看下面的例子。它基于冒险工作。在每个工资组的示例中,我根据其值返回每个产品类别的前三个子类别。

WITH 
MEMBER [Measures].[Internet Sales Amount Rank] AS
RANK( ([Product].[Category].currentmember,[Product].[Subcategory].CurrentMember),
ORDER( ([Product].[Category].currentmember,[Product].[Subcategory].[Subcategory].Members) , [Measures].[Internet Sales Amount], BDESC)
) 

select 
non empty
([Product].[Category].[Category],filter([Product].[Subcategory].[Subcategory],[Measures].[Internet Sales Amount Rank]<4))
on columns,
non empty 
([Customer].[Yearly Income].[Yearly Income],[Measures].[Internet Sales Amount])
on rows 
from [Adventure Works]

结果

enter image description here


0
投票

这是你的脚本。有很多大括号向Mondrian发出元组信号:

WITH 
MEMBER [Measures].[Top5] AS 
RANK ( 
  (
   [Product].[Product Category].currentmember
  ,[Product].[Brand Name].CurrentMember
  )
  , ORDER( 
      (
         [Product].[Product Category].currentmember
        ,[Product].[Brand Name].[Brand Name].Members
      ) 
      , [Measures].[Store Sales]
      , BDESC
    ) 
  ) 
SELECT
non empty 
(
  [Product].[Product Category].[Product Category]
 ,filter(
    [Product].[Brand Name].[Brand Name]
  , [Measures].[Top5]<6
   )
) on columns, 
non empty (
   [Yearly_Income].[Yearly Income],
   [Measures].[Store Sales]
) on rows 
from [projetDW];

也许尝试使用CROSSJOIN函数来生成元组:

WITH 
MEMBER [Measures].[Top5] AS 
RANK ( 
  CROSSJOIN(
   { [Product].[Product Category].currentmember }
  ,{ [Product].[Brand Name].CurrentMember }
  )
  , ORDER( 
      CROSSJOIN(
         { [Product].[Product Category].currentmember }
        ,[Product].[Brand Name].[Brand Name].Members
      ) 
      , [Measures].[Store Sales]
      , BDESC
    ) 
  ) 
SELECT
non empty 
CROSSJOIN(
  [Product].[Product Category].[Product Category].MEMBERS
 ,FILTER(
     [Product].[Brand Name].[Brand Name]
   , [Measures].[Top5]<6
  )
) on columns, 
non empty 
(
   [Yearly_Income].[Yearly Income],
   [Measures].[Store Sales]
) on rows 
from [projetDW];
© www.soinside.com 2019 - 2024. All rights reserved.