MDX - 从另一个日期维度计算一个日期维度
我有一个事实表,其中有 2 个日期发票日期
和会计当前日期
。为了获得请求的收入值,我需要使用这两个日期的组合。例如,如果我需要 YTD Revenue,我需要像这样选择它:
(注意:我正在编写 SQL 查询,因为我更熟悉它)
SELECT Revenue
FROM
Fact_Revenue
WHERE
Invoice_Date <= '2011-10-22'
and AccountingCurrent >= '2011-01'
and AccountingCurrent <= '2011-10'
除了 Revenue 之外,该事实表还包含我需要的其他信息也需要,但为了计算其他数据,我不需要会计当前日期
。所以我的想法是在主 MDX 查询中仅使用 1 个日期(发票日期
)(以便我可以通过 1 个查询获取尽可能多的数据),并且为了计算收入,我想使用计算会员,我想将会计当前日期
与选定的发票日期
关联起来。
例如
SELECT {[Measure].[RevenueYTD],
[Measure].[RevenueMTD],
[Measure].[NumberOfInvoices],
[Measure].[NumberOfPolicies]}
ON COLUMNS,
{[People].Members} ON ROWS
FROM [Cube]
WHERE
[Invoice Date].[Date Hierarchy].[Date].&[2011-10-22]
,在本例中,[Measure].[RevenueYTD]
和 [Measure].[RevenueMTD]
需要受到 会计当前日期
的限制并且发票日期
必须低于查询的日期。另一方面,我需要 [Measure].[NumberOfInvoices]
和 [Measure].[NumberOfPolicies]
来获取特定发票日期(或 MTD 日期,等等),但没有涉及 Accounting Current Date
计算的成员查询应该执行类似这样的操作(这更像是算法):
ROUND(
SUM(
YTD([Accounting Current Date].[Date Hierarchy].CurrentMember),
[Measures].[Revenue]
),
2)
WHERE [Invoice Current Date].[Date Hierarchy] < [Invoice Current Date].[Date Hierarchy].CurrentMember
I have a fact table that has 2 dates Invoice Date
and Accounting Current Date
. In order to get requested Revenue value I need to use combination of these two dates. For example, if I need YTD Revenue I need to select it like this:
(Note: I am writing SQL query because I am more familiar with it)
SELECT Revenue
FROM
Fact_Revenue
WHERE
Invoice_Date <= '2011-10-22'
and AccountingCurrent >= '2011-01'
and AccountingCurrent <= '2011-10'
Besides Revenue, this fact tables has other information that I also need, but for calculating this other data I don't need Accounting Current Date
. So my idea is to use only 1 date (Invoice Date
) in main MDX query (so that I can grab as many data with 1 query as I can) and for calculating Revenue I would like to use Calculated Member and in there I would like to associate Accounting Current Date
with selected Invoice Date
.
For example
SELECT {[Measure].[RevenueYTD],
[Measure].[RevenueMTD],
[Measure].[NumberOfInvoices],
[Measure].[NumberOfPolicies]}
ON COLUMNS,
{[People].Members} ON ROWS
FROM [Cube]
WHERE
[Invoice Date].[Date Hierarchy].[Date].&[2011-10-22]
In this case, [Measure].[RevenueYTD]
and [Measure].[RevenueMTD]
need to be limited by Accounting Current Date
and Invoice Date
must be lower than the date from the query. On the other hand, I need [Measure].[NumberOfInvoices]
and [Measure].[NumberOfPolicies]
for particual Invoice Date (or MTD Date, whatever), but without involvemenet of Accounting Current Date
Calculated member query should do something like this (this is more like algorithm):
ROUND(
SUM(
YTD([Accounting Current Date].[Date Hierarchy].CurrentMember),
[Measures].[Revenue]
),
2)
WHERE [Invoice Current Date].[Date Hierarchy] < [Invoice Current Date].[Date Hierarchy].CurrentMember
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 MDX 中,从一个维度导航到另一个维度并不是一件小事。理论上维度是独立的,因此标准语言缺少执行此操作的功能。您可以使用 StrToMember MDX 函数,但它很慢而且有点奇怪。
对于您的过滤器,让我们从第一个开始:
在 MDX 中,我们必须创建一个包含与表达式匹配的成员的集合。这可以使用 Range set 运算符来完成:
另一个过滤器很容易猜测:
MDX 版本:
也可以使用 过滤MDX功能如果您需要不同类型的过滤器。
现在我们需要分块并构建查询。一种可能的解决方案是使用设置切片器并在您不希望应用过滤器时覆盖这些值:
Navigating from one dimension to another is not something trivial in MDX. In theory dimensions are independent so standard language is missing functions for doing this. You can use StrToMember MDX function but it's slow and a bit strange.
For your filters, let's start with the first one :
In MDX we'll have to create a set with the members matching the expression. This can be done using the Range set operator :
The other filter is easy to guess :
MDX version :
It's also possible using Filter MDX function if your need different type of filters.
Now we need to take the pieces and build the query. One possible solution is using a set slicer and overwritting the values when you don't want the filter to be applied :