repository/ppt/landscape_blue_c.ppt
FoodMart 2000 OLAP Queries
long version
Unit Sales by Promotion Media Type
S1 Made axis scale thousands and made axis number
currency. I don't know if these are worth automating.
WITH
MEMBER Measures.[$Unit Sales]
AS 'Measures.[Unit Sales]', FORMAT_STRING = '#,#'
SELECT
{
[Measures].[$Unit Sales]
}
ON COLUMNS,
ORDER(
EXCEPT(
[Promotion Media].[Media Type].MEMBERS,
{[Promotion Media].[Media Type].[No Media]}
),
[Measures].[$Unit Sales],
DESC
)
ON ROWS
FROM [Sales]
Units Shipped and Ordered by Store
S2 heading row should be different - bold, orange?
SELECT
{
[Measures].[Units Shipped],
[Measures].[Units Ordered]
}
ON COLUMNS,
NON EMPTY
[Store].[Store Name].MEMBERS
ON ROWS
FROM [Warehouse]
Store Sales (last period) by Department
S3
WITH
MEMBER [Measures].[Store Sales Last Period]
AS '([Measures].[Store Sales], Time.PrevMember)', FORMAT_STRING = '$###,###'
SELECT
{
[Measures].[Store Sales Last Period]
}
ON COLUMNS,
{
TOPCOUNT(
[Product].[Product Department].MEMBERS,
5,
[Measures].[Store Sales Last Period]
)
}
ON ROWS
FROM Sales
WHERE ([Time].[1998])
Accumulated Sales
by Product Department
S4
WITH
MEMBER [Measures].[Total Store Sales]
AS 'Sum(YTD(),[Measures].[Store Sales])'
SELECT
{
[Measures].[Total Store Sales]
}
ON COLUMNS,
{
TOPCOUNT
(
[Product].[Product Department].MEMBERS,
5,
[Measures].[Total Store Sales]
)
}
ON ROWS
FROM Sales
WHERE
(
[Time].[1997].[Q2].[4]
)
Costs and Profit Rate
by Product Department
S5
WITH
MEMBER [Measures].[Store Profit Rate]
AS '([Measures].[Store Sales]-[Measures].[Store Cost])/[Measures].[Store Cost]', format = '#.00%'
SELECT
{
[Measures].[Store Cost],
[Measures].[Store Sales],
[Measures].[Store Profit Rate]
}
ON COLUMNS,
Order(
[Product].[Product Department].MEMBERS,
[Measures].[Store Profit Rate],
BDESC
)
ON ROWS
FROM Sales
WHERE ([Time].[1997])
Percent of Alcoholic Drinks
S6
WITH
MEMBER [Product].[All Products].[Drink].[Percent of Alcoholic Drinks]
AS '[Product].[All Products].[Drink].[Alcoholic Beverages]/[Product].[All Products].[Drink]', format = '#%'
SELECT
{
[Product].[All Products].[Drink].[Percent of Alcoholic Drinks]
}
ON COLUMNS,
ORDER
(
[Customers].[All Customers].[USA].[WA].CHILDREN,
[Product].[All Products].[Drink].[Percent of Alcoholic Drinks],
BDESC
)
ON ROWS
FROM Sales
WHERE ( [Measures].[Unit Sales] )
Sales and Accumulated Sales
by Month (1997)
S7
WITH
MEMBER Measures.[$Store Sales]
AS 'Measures.[Store Sales]', FORMAT_STRING = '$###,###'
MEMBER [Measures].[Accumulated Sales]
AS 'Sum(YTD(),[Measures].[Store Sales]) - [Measures].[Store Sales]', FORMAT_STRING = '$###,###'
SELECT
{
[Measures].[Accumulated Sales],
[Measures].[$Store Sales]
}
ON COLUMNS,
{
DESCENDANTS
(
[Time].[1997],
[Time].[Month]
)
}
ON ROWS
FROM Sales
Sales and Accumulated Sales
by Month (1997)
S7
WITH
MEMBER Measures.[$Store Sales]
AS 'Measures.[Store Sales]', FORMAT_STRING = '$###,###'
MEMBER [Measures].[Accumulated Sales]
AS 'Sum(YTD(),[Measures].[Store Sales]) - [Measures].[Store Sales]', FORMAT_STRING = '$###,###'
SELECT
{
[Measures].[Accumulated Sales],
[Measures].[$Store Sales]
}
ON COLUMNS,
{
DESCENDANTS
(
[Time].[1997],
[Time].[Month]
)
}
ON ROWS
FROM Sales
Ranked top 10 first-level managers
s9
WITH
SET [Leaves]
AS 'Descendants([Employees].[All Employees], 15, LEAVES )'
SET [Parents]
AS 'Generate( [Leaves], {[Employees].CurrentMember.Parent} )'
SET [FirstParents]
AS 'Filter( [Parents], Count( Descendants( [Employees].CurrentMember, 2 )) = 0 )'
SELECT
{
[Measures].[Number of Employees]
}
ON COLUMNS,
TOPCOUNT
(
[FirstParents],
10,
[Measures].[Number of Employees]
)
ON ROWS
FROM HR
Topcount Example
s10 - fix, make measures list explicit
SELECT
{
Measures.[Unit Sales],
Measures.[Store Cost]
}
ON COLUMNS,
TOPCOUNT
(
{
[Store].[Store City].MEMBERS
},
12,
Measures.[Sales Count]
)
ON ROWS
FROM [Sales]
Descendents example
s12 - fix, make measures list explicit
WITH
MEMBER Measures.[$Unit Sales]
AS 'Measures.[Unit Sales]', FORMAT_STRING = '#,#'
MEMBER Measures.[$Store Cost]
AS 'Measures.[Store Cost]', FORMAT_STRING = '$###,###'
MEMBER Measures.[$Store Sales Net]
AS 'Measures.[Store Sales Net]', FORMAT_STRING = '$###,###'
SELECT
{
Measures.[$Unit Sales],
Measures.[$Store Cost],
Measures.[$Store Sales Net]
}
ON COLUMNS,
{
[Store].[Store State].[CA],
DESCENDANTS
(
[Store].[Store State].[CA],
[Store City],
SELF
)
}
ON ROWS
FROM [Sales]
Store Profit
for the first quarter of each year
s14
WITH
MEMBER Measures.[$Profit]
AS 'Measures.[Profit]', FORMAT_STRING = '$###,###'
SET [Quarter1]
AS 'GENERATE([Time].[Year].MEMBERS, {[Time].CURRENTMEMBER.FIRSTCHILD})'
SELECT
[Quarter1]
ON COLUMNS,
NON EMPTY
[Store].[Store Name].MEMBERS
ON ROWS
FROM [Sales]
WHERE
(
Measures.[$Profit]
)
Sales of a Product Brand
as a percentage of the sales of that product within its subcategory
s15
WITH
MEMBER Measures.[$Unit Sales]
AS 'Measures.[Unit Sales]', FORMAT_STRING = '#,#'
MEMBER MEASURES.[Percentage Sales]
AS '([Product].CURRENTMEMBER, Measures.[Unit Sales]) / ([Product].CURRENTMEMBER.PARENT, Measures.[Unit Sales])', FORMAT_STRING = '#.00%'
SELECT
{
MEASURES.[$Unit Sales],
MEASURES.[Percentage Sales]
}
ON COLUMNS,
HEAD([Product].[Brand Name].MEMBERS,20)
ON ROWS
FROM [Sales]
Percentage of sales for top 10 promotion
compared only to other promotions
s17
WITH
MEMBER Measures.[$Unit Sales]
AS 'Measures.[Unit Sales]', FORMAT_STRING = '#,#'
SET [PromotionSales]
AS 'EXCEPT({[Promotions].[All Promotions].CHILDREN}, {[Promotions].[No Promotion]})'
MEMBER Measures.[Percentage Sales]
AS '([Promotions].CURRENTMEMBER, Measures.[Unit Sales]) / SUM([PromotionSales], Measures.[Unit Sales])', FORMAT_STRING = '#.00%'
SELECT
{
Measures.[$Unit Sales],
Measures.[Percentage Sales]
}
ON COLUMNS,
TOPCOUNT(
[PromotionSales],
10,
Measures.[Percentage Sales]
)
ON ROWS
FROM [Sales]
Sales Growth Over Time
s19
WITH
MEMBER Measures.[$Profit]
AS 'Measures.[Profit]', FORMAT_STRING = '$###,###'
MEMBER Measures.[Profit Growth]
AS '(Measures.[Profit]) - (Measures.[Profit], [Time].PREVMEMBER)', FORMAT_STRING = '$###,###'
SELECT
{
Measures.[$Profit],
Measures.[Profit Growth]
}
ON COLUMNS,
{
DESCENDANTS(
[Time].[1997],
[Month]
)
}
ON ROWS
FROM [Sales]
Monthly Year-to-Date Sales
for each product category in 1997
s22
WITH
MEMBER Measures.YTDSales
AS 'SUM(YTD(), Measures.[Store Sales])', FORMAT_STRING = '$#,#.00'
SELECT
{
DESCENDANTS
(
[Time].[1997],
[Month]
)
}
ON COLUMNS,
{
HEAD([Product].[Product Category].MEMBERS,10)
}
ON ROWS
FROM [Sales]
WHERE
(
Measures.YTDSales
)
Store Sales Profit
for those whose unit sales exceed 25,000 in 1997 for each city \rbased against the store type
s23
WITH
MEMBER Measures.[$Profit]
AS 'Measures.[Profit]', FORMAT_STRING = '$###,###'
SELECT
NON EMPTY
{
[Store Type].[Store Type].MEMBERS
}
ON COLUMNS,
FILTER
(
{
[Store].[Store City].MEMBERS
},
(
Measures.[Unit Sales],
[Time].[1997]
) > 25000
)
ON ROWS
FROM [Sales]
WHERE
(
Measures.[$Profit],
[Time].[Year].[1997]
)
Top Dozen Stores by Sales Count
s25 Trick here was to properly format calculated member
WITH
MEMBER Measures.[$Unit Sales]
AS 'Measures.[Unit Sales]', FORMAT_STRING = '#,#'
MEMBER Measures.[$Store Cost]
AS 'Measures.[Store Cost]', FORMAT_STRING = '$###,###'
MEMBER Measures.[$Store Sales Net]
AS 'Measures.[Store Sales Net]', FORMAT_STRING = '$###,###'
SET TopCities
AS 'TOPCOUNT([Store].[Store City].MEMBERS, 12, [Sales Count])'
MEMBER [Store].[Other Cities]
AS '([Store].[All Stores], Measures.CURRENTMEMBER) - SUM(TopCities, Measures.CURRENTMEMBER)'
SELECT
{
Measures.[$Unit Sales],
Measures.[$Store Cost],
Measures.[$Store Sales Net]
}
ON COLUMNS,
{
TopCities,
[Store].[Other Cities]
}
ON ROWS
FROM [Sales]
Sales Measures
for cities whose sales count accounts for 50 percent of all the sales
s26
WITH
MEMBER Measures.[$Store Cost]
AS 'Measures.[Store Cost]', FORMAT_STRING = '$###,###'
MEMBER Measures.[$Store Sales Net]
AS 'Measures.[Store Sales Net]', FORMAT_STRING = '$###,###'
SELECT
{
Measures.[Unit Sales],
Measures.[$Store Cost],
Measures.[$Store Sales Net]
}
ON COLUMNS,
TOPPERCENT
(
{
[Store].[Store City].MEMBERS
},
50,
Measures.[Sales Count]
)
ON ROWS
FROM [Sales]
Unit Sales and Customer Count
by product category
s28
WITH
MEMBER Measures.[$Unit Sales]
AS 'Measures.[Unit Sales]', FORMAT_STRING = '#,#'
MEMBER Measures.[Customer Count]
AS 'COUNT(CROSSJOIN({Measures.[Unit Sales]}, [Customers].[Name].MEMBERS), EXCLUDEEMPTY)'
SELECT
{
Measures.[$Unit Sales],
Measures.[Customer Count]
}
ON COLUMNS,
{
HEAD ([Product].[Product Category].MEMBERS, 10)
}
ON ROWS
FROM [Sales]
Unit Sales and Percent of States Sales
by store
s29 This would be great as a series of pie charts !!!
WITH
MEMBER MEASURES.[Percentage Sales]
AS '([Store].CURRENTMEMBER,MEASURES.[Unit Sales]) / ([Store].CURRENTMEMBER.PARENT,MEASURES.[Unit Sales])',FORMAT_STRING = '#%'
SELECT
{
MEASURES.[Unit Sales],
MEASURES.[Percentage Sales]
}
ON COLUMNS,
NON EMPTY
{
[Store].[Store City].MEMBERS
}
ON ROWS
FROM [Sales]
Percentage Profit for States
months 1997
s30 real crosstab - perhaps a heatmap?
WITH
MEMBER MEASURES.[Percent Profit]
AS '([Measures].[Store Sales]-[Measures].[Store Cost])/([Measures].[Store Cost])', FORMAT_STRING = '#%', SOLVE_ORDER = 1
SELECT
{
DESCENDANTS(
[Time].[1997],
[Time].[Month]
)
}
ON COLUMNS,
{
[Store].[Store Country].[USA].CHILDREN
}
ON ROWS
FROM [Sales]
WHERE
(
MEASURES.[Percent Profit]
)
Aggregated Store Sqft Member Property
s32
WITH MEMBER [Measures].[StoreSqft] AS
'IIF(
([Store].CurrentMember.Level.Name="Store Name"),
VAL(
[Store].CurrentMember.Properties("Store Sqft")
),
SUM(
DESCENDANTS(
[Store].currentmember,[Store].[Store Name]
),
VAL(
[Store].CurrentMember.Properties("Store Sqft")
)
)
)'
SELECT
{
[Measures].[StoreSqft]
}
ON COLUMNS,
FILTER(
DESCENDANTS(
[Store].[All Stores],[Store].[Store State]
),
[Measures].[StoreSqft] > 0
)
ON ROWS
FROM [Sales]
Top Store Costs by City
s34 Try as pie
WITH
SET Top5Cities AS
'TOPCOUNT([Store].[Store City].MEMBERS, 5, [Store Cost])'
MEMBER Measures.[$Store Cost]
AS 'Measures.[Store Cost]', FORMAT_STRING = '$###,###'
MEMBER [Store].[Other Cities] AS
'([Store].[All Stores], [Store Cost]) - SUM(Top5Cities, [Store Cost])'
SELECT
{
Measures.[$Store Cost]
}
ON COLUMNS,
{
Top5Cities, [Store].[Other Cities]
}
ON ROWS
FROM [Sales]
Store Sales by Month
with +/- 3 St.Dev. Control
With [store sales] in the middle, I am getting format="#"
for the first column, because of my logic looking for
"IND" and setting value=0. The quick solution is perhaps
to make the [store sales] first - if this is the column
from which chart is getting its axis format. I've comfirmed
that putting it first fixed the chart axis - so it looks
like it does indeed come from the first one.
WITH
MEMBER Measures.[$Store Sales]
AS 'Measures.[Store Sales]', FORMAT_STRING = '$###,###'
MEMBER [Measures].[Rolling Sales] AS
'AVG(LASTPERIODS(3), [Store Sales])'
MEMBER [Measures].[Deviations] AS
'3 * STDDEV(LASTPERIODS(12), [Store Sales])'
MEMBER [Measures].[Upper Limit] AS
'[Rolling Sales] + [Deviations]', FORMAT_STRING = '$###,###'
MEMBER [Measures].[Lower Limit] AS
'[Rolling Sales] - [Deviations]', FORMAT_STRING = '$###,###'
SELECT
{
[$Store Sales], [Upper Limit], [Lower Limit]
}
ON COLUMNS,
DESCENDANTS(
[Time].[1997], [Time].[Month]
)
ON ROWS
FROM [Sales]
Store Sales Growth by Product
Month-to-Month 1997
s39
WITH
SET [Months] AS
'EXCEPT( DESCENDANTS([Time].[1997],[Time].[Month]), {[Time].[1997].[Q1].[1]} )'
MEMBER [Measures].[Growth] AS
' ((Time.CURRENTMEMBER, [Store Sales]) - (Time.PREVMEMBER, [Store Sales])) / (Time.PREVMEMBER, [Store Sales])', FORMAT_STRING = '#.00%'
MEMBER [Measures].[Avg Growth] AS 'Avg( [Months], [Growth] )'
MEMBER [Measures].[Rem] AS '1 - [Avg Growth]'
SELECT
{
[Avg Growth],
[Rem]
}
ON COLUMNS,
TOPCOUNT(
[Product].[Product Category].MEMBERS,
10,
[Avg Growth]
)
ON ROWS
FROM [Sales]