在SSAS AdventureWorks模式中,我试图找出有多少不同客户的Internet订单金额超过1000美元。
我试图像这样进行MDX查询,但它似乎几乎可以用,只是新措施似乎忽略了切片器的轴/WHERE
条件,它显示了所有国家(而不仅仅是澳大利亚)的客户数量:
With
member [measures].[DistinctCustomersHighSales] as
distinctcount(
filter([Customer].[Full Name].Members, [Measures].[Internet Sales-Sales Amount] > 1000)
)
SELECT {
[Measures].[Internet Sales-Sales Amount],
[Measures].[DistinctCustomersHighSales]
}
on columns,
([Date].[Calendar Date].[Calendar Year].Members) on rows
FROM [Analysis Services Tutorial]
WHERE [Customer].[Customer Geography].[Country-Region].[Australia]
我究竟做错了什么?
如果我在SQL中执行此操作,那么我将寻找类似的内容
SELECT Year(OrderDate) as year,
sum(SalesAmount)
count(case when count(distinct case when SalesAmount > 1000 then dc.customerkey end)
FROM dbo.FactInternetSales fis
join dbo.dimcustomer dc on fis.CustomerKey=dc.CustomerKey
join dbo.DimGeography dg on dc.GeographyKey=dg.GeographyKey
WHERE EnglishCountryRegionName='Australia'
GROUP BY year(OrderDate)
ORDER BY year
尝试添加EXISTING
:
With
member [measures].[DistinctCustomersHighSales] as
distinctcount(
filter(EXISTING [Customer].[Full Name].Members, [Measures].[Internet Sales-Sales Amount] > 1000)
)
SELECT {
[Measures].[Internet Sales-Sales Amount],
[Measures].[DistinctCustomersHighSales]
}
on columns,
([Date].[Calendar Date].[Calendar Year].Members) on rows
FROM [Analysis Services Tutorial]
WHERE [Customer].[Customer Geography].[Country-Region].[Australia]
范围是MDX中非常重要的概念。仅当添加时EXISTING
,引擎才会实现切片器。
成员定义中的初始集合是:
[Customer].[Full Name].Members
集在MDX中是静态的。因此,此集合默认包含所有客户。在添加时EXISTING
,在形成集合之前,将检查上下文。根据多维数据集中的维使用(关系),它可以过滤属于澳大利亚的客户。这样就可以了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句