如何根据 mdx 中的另一个属性对一个属性进行分组
How to group one attribute based on another attribute in mdx
我想从 mdx
查询中获取分层输出。从以下查询中,它以平面方式为我提供了输出。就像所有的公司都给出 'All' 的结果,然后它开始给出 'Pharmacy' 的结果,依此类推。
但我希望每个公司都像下面这样。
这是我编写的 mdx
查询:
WITH
SET Last36Months AS
LastPeriods
(36
,[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
)
SET LatestMonth AS
{
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(24),
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(12),
[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
}
MEMBER [Measures].[UnitSales] AS
(
Last36Months
,[Measures].[SALES UNITS (000)]
)
MEMBER [Measures].[ValueSales] AS
(
Last36Months
,[Measures].[SALES VALUES (000)]
)
SELECT
{
(
LatestMonth
,[Measures].[SALES VALUES (000)]
)
,(
LatestMonth
,[Measures].[SALES UNITS (000)]
)
} ON 0
,{
Order
(
NonEmpty
(
(
[CHANNEL].[Channel].[All]
,[MARKET BASE].[Market Base].&[1]
,[CORPORATION].[Corporation].[Corporation].MEMBERS
)
)
+
NonEmpty
(
(
Descendants
(
[CHANNEL].[Channel].[All]
,1
)
,[MARKET BASE].[Market Base].&[1]
,[CORPORATION].[Corporation].[Corporation].MEMBERS
)
)
,[CORPORATION].[Corporation].[Corporation].Name
,bdesc
)
} ON 1
FROM [PharmaTrend Monthly Stand Reg];
您似乎想按 [CORPORATION].[Corporation]
层次结构中的成员名称排序。
在那种情况下,下面应该有效:
with set Last36Months as
LASTPERIODS(36, [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1])
Set LatestMonth as
{
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(24),
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(12),
[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
}
member [Measures].[UnitSales] as
(Last36Months,[Measures].[SALES UNITS (000)])
member [Measures].[ValueSales] as
(Last36Months,[Measures].[SALES VALUES (000)])
member [Measures].CorporationName as
[CORPORATION].[Corporation].currentmember.membervalue
set OrderedSet as
order(
(
nonempty(([CHANNEL].[Channel].[All],[MARKET BASE].[Market Base].&[1], [CORPORATION].[Corporation].[Corporation].members))+
nonempty((descendants([CHANNEL].[Channel].[All],1),[MARKET BASE].[Market Base].&[1],[CORPORATION].[Corporation].[Corporation].members))
)
,[Measures].CorporationName
,bdesc)
select
{
(LatestMonth,[Measures].[SALES VALUES (000)]),
(LatestMonth,[Measures].[SALES UNITS (000)])
} on 0,
OrderedSet on 1
from [PharmaTrend Monthly Stand Reg]
您不需要创建自定义集 - 您可以坚持将 ORDER
包含在 SELECT
:
中的最初想法
WITH
SET Last36Months AS
LastPeriods
(36
,[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
)
SET LatestMonth AS
{
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(24),
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(12),
[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
}
MEMBER [Measures].[UnitSales] AS
(
Last36Months
,[Measures].[SALES UNITS (000)]
)
MEMBER [Measures].[ValueSales] AS
(
Last36Months
,[Measures].[SALES VALUES (000)]
)
SELECT
{
(
LatestMonth
,[Measures].[SALES VALUES (000)]
)
,(
LatestMonth
,[Measures].[SALES UNITS (000)]
)
} ON 0
,Order
(
NonEmpty
(
(
[CHANNEL].[Channel].[All]
,[MARKET BASE].[Market Base].&[1]
,[CORPORATION].[Corporation].[Corporation].MEMBERS
)
)
+
NonEmpty
(
(
Descendants
(
[CHANNEL].[Channel].[All]
,1
)
,[MARKET BASE].[Market Base].&[1]
,[CORPORATION].[Corporation].[Corporation].MEMBERS
)
)
,[CORPORATION].[Corporation].CurrentMember.MemberValue
,bdesc
) ON 1
FROM [PharmaTrend Monthly Stand Reg];
我想从 mdx
查询中获取分层输出。从以下查询中,它以平面方式为我提供了输出。就像所有的公司都给出 'All' 的结果,然后它开始给出 'Pharmacy' 的结果,依此类推。
但我希望每个公司都像下面这样。
这是我编写的 mdx
查询:
WITH
SET Last36Months AS
LastPeriods
(36
,[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
)
SET LatestMonth AS
{
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(24),
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(12),
[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
}
MEMBER [Measures].[UnitSales] AS
(
Last36Months
,[Measures].[SALES UNITS (000)]
)
MEMBER [Measures].[ValueSales] AS
(
Last36Months
,[Measures].[SALES VALUES (000)]
)
SELECT
{
(
LatestMonth
,[Measures].[SALES VALUES (000)]
)
,(
LatestMonth
,[Measures].[SALES UNITS (000)]
)
} ON 0
,{
Order
(
NonEmpty
(
(
[CHANNEL].[Channel].[All]
,[MARKET BASE].[Market Base].&[1]
,[CORPORATION].[Corporation].[Corporation].MEMBERS
)
)
+
NonEmpty
(
(
Descendants
(
[CHANNEL].[Channel].[All]
,1
)
,[MARKET BASE].[Market Base].&[1]
,[CORPORATION].[Corporation].[Corporation].MEMBERS
)
)
,[CORPORATION].[Corporation].[Corporation].Name
,bdesc
)
} ON 1
FROM [PharmaTrend Monthly Stand Reg];
您似乎想按 [CORPORATION].[Corporation]
层次结构中的成员名称排序。
在那种情况下,下面应该有效:
with set Last36Months as
LASTPERIODS(36, [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1])
Set LatestMonth as
{
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(24),
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(12),
[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
}
member [Measures].[UnitSales] as
(Last36Months,[Measures].[SALES UNITS (000)])
member [Measures].[ValueSales] as
(Last36Months,[Measures].[SALES VALUES (000)])
member [Measures].CorporationName as
[CORPORATION].[Corporation].currentmember.membervalue
set OrderedSet as
order(
(
nonempty(([CHANNEL].[Channel].[All],[MARKET BASE].[Market Base].&[1], [CORPORATION].[Corporation].[Corporation].members))+
nonempty((descendants([CHANNEL].[Channel].[All],1),[MARKET BASE].[Market Base].&[1],[CORPORATION].[Corporation].[Corporation].members))
)
,[Measures].CorporationName
,bdesc)
select
{
(LatestMonth,[Measures].[SALES VALUES (000)]),
(LatestMonth,[Measures].[SALES UNITS (000)])
} on 0,
OrderedSet on 1
from [PharmaTrend Monthly Stand Reg]
您不需要创建自定义集 - 您可以坚持将 ORDER
包含在 SELECT
:
WITH
SET Last36Months AS
LastPeriods
(36
,[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
)
SET LatestMonth AS
{
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(24),
// [Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1].lag(12),
[Period JNJ].[Period Type-Year-Period].[Periods].&[MTH1]
}
MEMBER [Measures].[UnitSales] AS
(
Last36Months
,[Measures].[SALES UNITS (000)]
)
MEMBER [Measures].[ValueSales] AS
(
Last36Months
,[Measures].[SALES VALUES (000)]
)
SELECT
{
(
LatestMonth
,[Measures].[SALES VALUES (000)]
)
,(
LatestMonth
,[Measures].[SALES UNITS (000)]
)
} ON 0
,Order
(
NonEmpty
(
(
[CHANNEL].[Channel].[All]
,[MARKET BASE].[Market Base].&[1]
,[CORPORATION].[Corporation].[Corporation].MEMBERS
)
)
+
NonEmpty
(
(
Descendants
(
[CHANNEL].[Channel].[All]
,1
)
,[MARKET BASE].[Market Base].&[1]
,[CORPORATION].[Corporation].[Corporation].MEMBERS
)
)
,[CORPORATION].[Corporation].CurrentMember.MemberValue
,bdesc
) ON 1
FROM [PharmaTrend Monthly Stand Reg];