简体   繁体   English

MDX:在同一查询中使用不同日期期间组合两个查询结果

[英]MDX: Combine two queries results using different date periods in the same query

I need to do a measure comparison using the same dimensions, but with different date periods.我需要使用相同的维度进行度量比较,但日期周期不同。 Ex: "In week 2 the measure A was 15% better than week 1 for customer X".例如:“在第 2 周,客户 X 的措施 A 比第 1 周好 15%”。 ( I have daily granularity ) (我有每日粒度)

But I need to do all this in a single SSAS call, in a single MDX.但我需要在单个 SSAS 调用中,在单个 MDX 中完成所有这些工作。 Today I call the two queries separately in a C# program, and in the C# I combine the results and give the percentual difference.今天我在 C# 程序中分别调用这两个查询,在 C# 中我结合结果并给出百分比差异。

Below a example of what I do today:下面是我今天做的一个例子:

"CustomerX want to know the percentual difference of MyMeasureA in a comparison between week2 and week1 ( DateDim with daily granularity ) “CustomerX 想知道 MyMeasureA 在第 2 周和第 1 周之间的比较中的百分比差异(DateDim 与每日粒度)

So, first I do the query of the first week separately using the C# program:所以,首先我使用 C# 程序分别做第一周的查询:

select
measures.MyMeasureA on 0
from MyCube
where
( CustomerDim.CustomerX,
  { DateDim.Date.[1] : DateDim.Date[7] } )

I save the result above in my C# program.我将上面的结果保存在我的 C# 程序中。 After that I do the second query using the C#:之后,我使用 C# 进行第二次查询:

select
measures.MyMeasureA on 0
from MyCube
where
( CustomerDim.CustomerX,
  { DateDim.Date.[8] : DateDim.Date[14] } )

And I save the result in my C# program.我将结果保存在我的 C# 程序中。 After that, in the C# I combine the 2 results and do the percentual difference and tell to the customer: "In week2 your MeasureA was 4% better than the week1"之后,在 C# 中,我结合 2 个结果并计算百分比差异并告诉客户:“在第 2 周,您的 MeasureA 比第 1 周好 4%”

So what I need is do the 2 queries and the percentual in one SSAS call.所以我需要的是在一个 SSAS 调用中执行 2 个查询和百分比。 Do the queries and the percentual difference in a single call.在一次调用中执行查询和百分比差异。 The percentual is not a problem, but do the two queries in a single mdx is the problem for me.百分比不是问题,但是在一个 mdx 中执行两个查询对我来说是个问题。

Best Regards此致

Luis路易斯

You can create 2 tuples as measures in a WITH clause:您可以在 WITH 子句中创建 2 个元组作为度量:

WITH
MEMBER measures.MyMeasureX AS
(
  measures.MyMeasureA,
  CustomerDim.CustomerX,
  { DateDim.Date.[1] : DateDim.Date[7] } 
)
MEMBER measures.MyMeasureY AS
(
  measures.MyMeasureA,
  CustomerDim.CustomerX,
  { DateDim.Date.[8] : DateDim.Date[14] } 
)
SELECT
{
 measures.MyMeasureX,
 measures.MyMeasureY
} ON 0
FROM MyCube;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM