我需要比较不同商店自开业以来每周和每月的交易次数。问题是这些商店的开业日期不同。
所以,这个想法是比较前几周或几个月的交易数量
这就是我所拥有的:
Canal Key 1
Recount FactTransactions
Month1-2015 Month2-2015 Month3-2015 Month4-2015 Month5-2015 Month6-2015
Type of store Cod Store
Spain
2 Store 1 5 6 10
Store 2 10 20 40 50 60 85
4
Store 3 31 45 100 315 441 625
Store 4 10 20 32 45
Portugal
1
Store 5 12
Run Code Online (Sandbox Code Playgroud)
这就是我想要获得的(比较自开业之日起的不同商店):
Canal Key 1
Recount FactTransactions
Month1 (or Week) Month2 Month3 Month4 Month5 Month6
Type of store Cod Store
Spain
2 Store 1 5 6 10
Store 2 10 20 40 50 60 85
4
Store 3 31 45 100 315 441 625
Store 4 10 20 32 45
Portugal
1
Store 5 12
Run Code Online (Sandbox Code Playgroud)
这是我的数据模型:
FacTransaccion: *Measures* Recount FactTransaction / Amount / Amount discount / Unit Price
DimDate: *Hierachy* Date (YYYYMMDD) / Month / Month Name / Week of Month / Week of year / Year (It's the same Dimdate than AdventureWorksDW2008 with its member calculation and relationship)
DimProduct: *Hierachy* Product Key
DimStore: *Hierachy* Type of store / Store key / Opening date / Country
DimType: *Hierachy* Type of transaction
DimCanal: *Hierachy* Canal (there are two channel where people can buy)
Run Code Online (Sandbox Code Playgroud)
阅读了很多关于 MDX 的内容,经过一千次 MDX。我什么都没有。
几次尝试:
尝试#1:
SELECT CROSSJOIN({TAIL([Dim Store].[Opening date].Children, 30) }, { [Measures].[Transactiones] }) ON COLUMNS
,{ [Dim Store].[Store names].Children} ON ROWS FROM [CUBE]
Run Code Online (Sandbox Code Playgroud)
尝试#2:( 它不起作用)在我看来这比第一次尝试要好。
WITH MEMBER [Measures].[Count] AS
SUM([Dim Store].[Name Store].currentmember*Tail([Dim Store].[Opening Date].children,1),
[Measures].[Count Fact Transacciones])
SELECT {[Measures].[Count]} ON COLUMNS,
{[Dim Store].[Name Store].[All]} ON ROWS
from [CUBE]
Run Code Online (Sandbox Code Playgroud)
我们确实需要有关您的度量和维度的更多详细信息才能就此给出准确答案,但由于您使用的是 SSAS,因此适用一些通用规则。
如果您添加更多细节,我可以扩展我的答案以符合您的数据模型。
由于您想比较交易数量,因此您应该measure显示交易数量。
由于您想随着时间的推移比较它们,您还需要 aTime Dimension和hierarchy.
如果您同时具备这两个先决条件,则可以MDX通过维度层次结构和成员来计算度量的总和和差异。
从本质上讲,您需要尝试的是构建一个集合并总结您对该集合的度量。
Sum({[opening date]:[opening date+2weeks]},[Measures].[Number of transactions])
Run Code Online (Sandbox Code Playgroud)
您的问题中最困难的部分将是构建set然而。如果没有您的数据模型和一些示例数据,这就是我们无法回答的部分。
正如您所说,不同的商店有不同的开始日期,您可以在商店维度上使用一个属性来指示它的开始日期,并使用它来构建一个集合来总结。
开始使用 MDX 的一个很好的资源是SQL Server Central 上的Stairway to MDX 系列。
您应该查看PeriodsToDate 之类的函数。
您还可以选择使用VBA 函数,并且如果您无法使用纯 MDX 到达那里,可以使用它来使用DateDiff 和 DateAdd。
如果所有其他方法都失败了,您甚至可以编写自己的SSAS 存储过程。
| 归档时间: |
|
| 查看次数: |
249 次 |
| 最近记录: |