翻译介绍15个经典的MDX查询-04&05

来源:互联网 发布:智能配电网 知乎 编辑:程序博客网 时间:2024/05/29 10:57

 04,最近销售趋势最好的产品有哪些?

查询Listing 4首先利用TopCount()查得销售最好的产品,然后利用上个查询Listing 3介绍过的动态时间技巧定义最近6个月的销售量。该查询安排在行显示销售最好的10种产品,列显示最近的6个月,值区域为这6个月的Unit Sales。你可以用线状图展示该查询以便监视产品的销售绩效。

(注:这是比较常用的报表查询,特别是在KPI展示中。用TSQL也可以实现该报表的展示,但是将没有用MDX来得简洁,方便;因为AS在仓库建模的时候已经在后台做了多层预先的处理。)

Listing_04.Determining Recent Trends for Best-Selling Brands.txt

说明:查出最近6个月销售趋势最好的前10个商品及其各自销售量

with set [TenBest] as 'TopCount( [Product].[Brand Name].Members, 10, [Unit Sales] )'

set [LastMonth] as 'Tail(Filter([Time].[Month].Members,Not IsEmpty([Time].CurrentMember)),1)'

set [Last6Months] as ' [LastMonth].item(0).item(0).Lag(6) : [LastMonth].item(0).item(0)'

select [Last6Months] on COLUMNS,

[TenBest] on ROWS

from Sales

查询效果展示:


05, 哪些产品品牌构成公司(指超市)的前80%的销售量?

TopPercent()函数与TopCount()函数类似,只是TopPercent()返回的是最少项,如本例返回组成unit sales 80%的最少项(换句话说,这些项是unit sales数值大的项)。Listing 5 在行显示产品品牌,列及对应区域显示Total unit sales,从高到低排列。

Listing_05.Determining Brands that Make Up 80 Percent of Sales.txt

说明:找出组成销售额80%的商品销售及其记录;

select {[Unit Sales]} on COLUMNS,

TopPercent([Product].[Brand Name].Members, 80, [Unit Sales])on ROWS

from Sales

查询效果展示:



注:

TopCount

从集合顶端开始返回指定数目的项,可以选择首先对集合排序。

例子

SELECT {[Measures].[Store Sales] } ON COLUMNS,

Topcount(Descendants([Store].[All Stores].[USA],[Store].[Store City] ), 10, [store sales]) ON rows from sales

TopPercent

对集合排序,并返回顶端的 n 个元素,这些元素的累积合计至少为指定的百分比。

例子

SELECT {[Measures].[Store Sales] } ON COLUMNS,

TopPercent(Descendants([Store].[All Stores].[USA],[Store].[Store City] ), 90, [store sales]) ON rows from sales

原创粉丝点击