MDX - 如何在 MIN 聚合中跳过 0 值以及如何排除一定百分比的结果?
MDX - How skip 0 values in MIN agregation and how exclude some percent of results?
在我的立方体中我有
- 收入作为
MIN
聚合的衡量标准
- 维度:[本地化].[类型].&[中心]
- 维度:{[日期].[年份].&[2017],[日期].[年份].&[2018]}
我的查询是:
What are the minimum earnings of the person who decides to buy
apartments in the city center, excluding 5% of the lowest, within
last 2 years?
现在我的 mdx 查询如下所示:
SELECT
[Measures].[MinEarnings] ON COLUMNS
FROM [cube]
WHERE
(
BottomCount ([Localization].[Type].&[center], 95, [Measures].[MinEarnings]),
{[Date].[Year].&[2017], [Date].[Year].&[2018]}
)
我有两个问题:
- 一些收入为 0 - 我如何在计算中跳过它们?
- 我的查询是否正确排除了最低收入的 5%?
首先你应该使用toppercent而不是bottomcount。你想要一个不在最后 5% 而不是最后 5% 的人的最低工资。Toppercent 会给你前 95%。
其次要过滤 0,您可以使用以下语法
toppercent (
filter([Localization].[Type].&[center], [Measures].[MinEarnings]>0)
, 95, [Measures].[MinEarnings])
即使现在将代码放在 where 子句中也可能不起作用,但请尝试一下。我建议你将 toppercent 移动到 rows ,然后订购它,然后取 top1
topcount(
order(
toppercent (
filter([Localization].[Type].&[center], [Measures].[MinEarnings]>0)
,95, [Measures].[MinEarnings])
,[Measures].[MinEarnings],asc)
,1)
我有一个例子给出了城市的最小销售额,注意我已经用 0 替换了 null 以使其尽可能接近你的情况
成员[措施].[互联网销售额2]
作为
case when ([Measures].[Internet Sales Amount])=null then 0 else [Measures].[Internet Sales Amount] end
select [Measures].[Internet Sales Amount2]
on columns ,
topcount(order(toppercent(filter([Customer].[City].[City],[Measures].[Internet Sales Amount2]>0),95,[Measures].[Internet Sales Amount2]),[Measures].[Internet Sales Amount2],asc),1)
on rows
from [Adventure Works]
where [Customer].[Country].&[Canada]
下图是topcount 1之前的结果
在我的立方体中我有
- 收入作为
MIN
聚合的衡量标准 - 维度:[本地化].[类型].&[中心]
- 维度:{[日期].[年份].&[2017],[日期].[年份].&[2018]}
我的查询是:
What are the minimum earnings of the person who decides to buy
apartments in the city center, excluding 5% of the lowest, within
last 2 years?
现在我的 mdx 查询如下所示:
SELECT
[Measures].[MinEarnings] ON COLUMNS
FROM [cube]
WHERE
(
BottomCount ([Localization].[Type].&[center], 95, [Measures].[MinEarnings]),
{[Date].[Year].&[2017], [Date].[Year].&[2018]}
)
我有两个问题:
- 一些收入为 0 - 我如何在计算中跳过它们?
- 我的查询是否正确排除了最低收入的 5%?
首先你应该使用toppercent而不是bottomcount。你想要一个不在最后 5% 而不是最后 5% 的人的最低工资。Toppercent 会给你前 95%。
其次要过滤 0,您可以使用以下语法
toppercent (
filter([Localization].[Type].&[center], [Measures].[MinEarnings]>0)
, 95, [Measures].[MinEarnings])
即使现在将代码放在 where 子句中也可能不起作用,但请尝试一下。我建议你将 toppercent 移动到 rows ,然后订购它,然后取 top1
topcount(
order(
toppercent (
filter([Localization].[Type].&[center], [Measures].[MinEarnings]>0)
,95, [Measures].[MinEarnings])
,[Measures].[MinEarnings],asc)
,1)
我有一个例子给出了城市的最小销售额,注意我已经用 0 替换了 null 以使其尽可能接近你的情况
成员[措施].[互联网销售额2] 作为 case when ([Measures].[Internet Sales Amount])=null then 0 else [Measures].[Internet Sales Amount] end
select [Measures].[Internet Sales Amount2]
on columns ,
topcount(order(toppercent(filter([Customer].[City].[City],[Measures].[Internet Sales Amount2]>0),95,[Measures].[Internet Sales Amount2]),[Measures].[Internet Sales Amount2],asc),1)
on rows
from [Adventure Works]
where [Customer].[Country].&[Canada]
下图是topcount 1之前的结果