温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

FoodMart的15个mdx例子,绝对一一经过测试,保证正确

发布时间:2020-05-23 06:23:51 来源:网络 阅读:298 作者:happydagui 栏目:软件技术

下面的内容经过完整的测试,结合了网上看到的其他文章,修改整理。

测试环境如下:FoodMart的15个mdx例子,绝对一一经过测试,保证正确

  windows 2003 sp2

  mondrian-3.1.1.12687

  jdk1.6

  tomcat 5.5.23

LISTING 1: Determining Products Sold in Each State
说明:每个州(省)都在销售的产品
[en]
with set [SoldInUSA] as 'Filter([Product].[Brand Name].Members, Not IsEmpty( ([USA], [Unit Sales]) ))'
member [Measures].[SoldInState] as 'iif( IsEmpty(([Product].CurrentMember, [Unit Sales], [Customers].CurrentMember)), "No","Yes" )'
select [USA].children on COLUMNS,
[SoldInUSA] on ROWS
from Sales
where ([Measures].[SoldInState])

[cn]
with set [SoldInUSA] as 'Filter([Product].[Brand Name].Members, Not IsEmpty( ([美国], [Unit Sales]) ))'
member [Measures].[SoldInState] as 'iif( IsEmpty(([Product].CurrentMember, [Unit Sales], [Customers].CurrentMember)), "No","Yes" )'
select [美国].children on COLUMNS,
[SoldInUSA] on ROWS
from Sales
where ([Measures].[SoldInState])

LISTING 2: Determining Top 10 Product Categories
说明:列出销售额排名前十的产品类别
select {[Measures].[Unit Sales]} ON COLUMNS,
  TopCount([Product].[Product Category].Members, 10.0, [Measures].[Unit Sales]) ON ROWS
from [Sales]

Listing_03.Determining Brands Sold During the Past Three Quarters.txt 
说明:列出过去三个季度里都存在销售量的商品销售记录  
[en]
with set [LastQuarter] as 'Tail(Filter([Time].[Quarter].Members, Not IsEmpty([Time].CurrentMember)),1)'
set [Last3Quarters] as ' [LastQuarter].item(0).item(0).Lag(2) : [LastQuarter].item(0).item(0)'
select [Last3Quarters] on COLUMNS,
Non Empty Union(Descendants( [Food], [Product].[Brand Name] ), Descendants( [Drink],  [Product].[Brand Name] )) on ROWS
from Sales

[cn]
with set [LastQuarter] as 'Tail(Filter([Time].[Quarter].Members, Not IsEmpty([Time].CurrentMember)),1)'
set [Last3Quarters] as ' [LastQuarter].item(0).item(0).Lag(2) : [LastQuarter].item(0).item(0)'
select [Last3Quarters] on COLUMNS,
Non Empty Union(Descendants( [食品], [Product].[Brand Name] ), Descendants( [饮用类],  [Product].[Brand Name] )) on ROWS
from Sales

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

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

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

Listing_07.Determining the Top Five Stores and the Top Five Customers.txt
说明:查出销售量最好的前5名店和每个店的前5个顾客 及其销售记录  
select {[Unit Sales]} on COLUMNS,
Generate( TopCount([Store].[Store Name].Members, 5, [Unit Sales]),
{ [Store].CurrentMember } * TopCount( [Customers].[Name].Members, 5, ([Unit Sales], 
[Store].CurrentMember) ) ) on ROWS
from Sales

Listing_08.Determining Two Top-Selling Products.txt
说明:查出每种产品大类 前2名 产品小类型号的销售记录,以及小类型号占大类的百分比  
with member [Measures].[PercTotalSales] as
' Sum( TopCount([Product].CurrentMember.Children, 2, [Unit Sales]), [Unit Sales] ) 
/([Product].CurrentMember, [Unit Sales])',
FORMAT_STRING = '##.0%'
select [Store].[(All)].Members on COLUMNS,
  Generate( [Product].[Brand Name].Members, 
   Union(
      TopCount( [Product].CurrentMember.Children, 2, [Unit Sales] ) * {[Unit Sales]},
      { ([Product].CurrentMember, [Measures].[PercTotalSales]) }
      )
   ) on ROWS
from Sales

===============================

Listing_09.Highlighting Products in the Bottom 10 Percent.txt

说明:查出4个季度中,每个时期销售量在后10%的产品销售量,并显示为粗体  
with set [LastQuarter] as 'Tail(Filter([Time].[Quarter].Members, Not 
IsEmpty([Time].CurrentMember)))'
set [Last4Quarters] as ' [LastQuarter].item(0).item(0).Lag(3) : [LastQuarter].item(0).item(0)'
member [Measures].[HLUnit Sales] as '[Unit Sales]',
  FONT_FLAGS = 'iif( Count(
       Intersect( BottomPercent( [Product].[Brand Name].Members, 10, ([Unit Sales]) ), 
{[Product].CurrentMember})
       ) = 0, 0, 1)'
select [Last4Quarters] on COLUMNS,
  [Product].[Brand Name].Members on ROWS
from Sales
where ([Measures].[HLUnit Sales])
cell properties VALUE, FORMATTED_VALUE, FONT_FLAGS

Listing_10.Comparing Sales with Those of Parallel Months.txt
说明:比较具有相同相对位置的时间点的销售量,例如今年7月和去年7月;  
with set [PromoMonths] as 'Filter([Time].[Month].Members, Not IsEmpty( ([Unit Sales], [Double Your Savings]) ) )'
  set [PromoRange] as 'Head( [PromoMonths] ).item(0).item(0) : Tail( [PromoMonths] ).item(0).item(0)'
member [Measures].[Uplift] as '([Unit Sales], [Double Your Savings])'
member [Measures].[This Quarter] as '[Unit Sales]'
member [Measures].[Last Quarter] as '( ParallelPeriod( [Time].[Quarter] ), [Unit Sales] )'
member [Measures].[Growth] as ' [Measures].[This Quarter] - [Measures].[Last Quarter]'

select [PromoRange] on Columns,
{ [Measures].[This Quarter], [Measures].[Last Quarter], [Measures].[Growth], [Measures].[Uplift] } on Rows
from [Sales]

Listing_11.Determining Sales That Exceed Store Cost by 160 Percent.txt
说明:查出利润率在16%以上的产品及销售记录  
with member [Measures].[SalesRatio] as '([Store Sales] - [Store Cost]) / [Store Cost]', 
FORMAT_STRING = '##%'
select { [Store Sales], [Store Cost], [Measures].[SalesRatio] } on COLUMNS,
Filter( [Product].[Brand Name].Members, [Measures].[SalesRatio] > 1.60 ) on  ROWS
from Sales

Listing_12.Determining Brands that Have Grown by More Than 50 Percent.txt
说明:找出最近一季度比前一季度销售量增长幅度大于50%的产品销售记录  
with set [LastQuarter] as 'Tail(Filter([Time].[Quarter].Members, Not 
IsEmpty([Time].CurrentMember)))'
  member [Measures].[CurrQSales] as '([LastQuarter].item(0).item(0), [Unit Sales])'
  member [Measures].[PrevQSales] as '([LastQuarter].item(0).item(0).PrevMember, [Unit Sales])'
  member [Measures].[Growth] as ' ([Measures].[CurrQSales] - [Measures].[PrevQSales]) / [Measures].[PrevQSales]', 
FORMAT_STRING='##%'
select { [Measures].[PrevQSales], [Measures].[CurrQSales], [Measures].[Growth] } on COLUMNS,
  Filter( [Product].[Brand Name].Members, [Measures].[Growth] > 0.5 ) on ROWS
from Sales

Listing_13.Determing the Top 10 and Bottom 10 Product Brands.txt
说明:找出销售额在前、后10名的产品销售记录,并列出总排名,就是找出销售情况最好和最坏的产品  
with set [OrderedBrands] as 'Order( [Product].[Brand Name].Members, [Unit Sales], BDESC )'
  member [Measures].[Brand Rank] as 'Rank( [Product].CurrentMember, [OrderedBrands] )'
select {[Measures].[Brand Rank], [Unit Sales]} on COLUMNS,
  Union( Head( [OrderedBrands], 10 ), Tail( [OrderedBrands], 10 ) ) on ROWS
from Sales

Listing_14.Comparing Product Trends.txt
说明:比较一下产品销售趋势,没什么用  
with set [LastQuarter] as 'Tail(Filter([Time].[Quarter].Members, Not 
IsEmpty([Time].CurrentMember)))'
set [Last4Quarters] as ' [LastQuarter].item(0).item(0).Lag(3) : [LastQuarter].item(0).item(0)'
member [Measures].[GroupAvg] as 'Avg([Product].CurrentMember.Siblings, [Unit Sales])'
member [Measures].[AllAvg] as 'Avg( [Product].[Product Name].Members, [Unit Sales])'
select [Last4Quarters] on COLUMNS,
{ [Unit Sales], [Measures].[GroupAvg], [Measures].[AllAvg] } on ROWS
from Sales
/*where ([Ebony Plums])*/

Listing_15.Determining the Top 10 Middle-Tier Brands.txt
说明:查出一定条件下的前10名产品的销售记录,例如销售量在500到3000之间的  
with set [LastQuarter] as 'Tail(Filter([Time].[Quarter].Members, Not 
IsEmpty([Time].CurrentMember)))'
set [Last4Quarters] as ' [LastQuarter].item(0).item(0).Lag(3) : [LastQuarter].item(0).item(0)'
member [Measures].[GroupAvg] as 'Avg([Product].CurrentMember.Siblings, [Unit Sales])'
member [Measures].[AllAvg] as 'Avg( [Product].[Product Name].Members, [Unit Sales])'
member [measures].[abc] as '[Product].CurrentMember.uniquename'
select [Last4Quarters] on COLUMNS,
{ [Unit Sales], [measures].[GroupAvg], [measures].[AllAvg],[measures].[abc] } on ROWS
from Sales
/*where ([Ebony Plums])*/

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI