4.最近销售趋势最好的产品有哪些?
查询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
查询效果展示:
5, 哪些产品品牌构成公司(指超市)的前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 |
6. 那些产品构成销量总量最少的20%?
查询Listing 6 用BottomPercent()返回仅构成Total unit sales 20%的最多的产品项,也就是说,这些产品的unit sales 最小。查询用关键字Non Empty排除了没有销售量的产品。需要注意的是,Non Empty跟Filter()与IsEmpty()的组合使用(见Listing 3)略有不同,因为Non Empty最用在某个轴(如rows)的所有项上。
Listing_06.Determining Brands That Make Up the Bottom 20 Percent of Sales.txt
说明:按销售量排序,找出组成20%销售量的商品销售记录
select {[Unit Sales]} on COLUMNS,
Non Empty BottomPercent([Product].[Brand Name].Members, 20, [Unit Sales]) on ROWS
from Sales
查询结果表展示:
查询结果图展示: