创建 MDX 计算成员以使用包含总计和缩减的数据制作堆积条形图

发布于 2024-09-06 17:26:57 字数 1729 浏览 1 评论 0原文

我们使用 SSAS 中构建的多维数据集,我们希望显示增量对预测的影响。

因此,我们有这样的数据:

Year    Type        Amount
----    ---------   ---------
2008    Forecast    +1000
2008    Delta 1     - 100
2008    Delta 2     - 200
2009    ...

我们想要制作一个堆积条形图,因此我们需要这样的数据:

Year    Type        Amount
----    ---------   ---------
2008    Result      +700
2008    Delta 1     +100
2008    Delta 2     +200

您可以看到“结果”等于特定粒度的预测和增量之和(在此示例中)如果只是时间,我们还会有地方作为附加维度)。

问题是我们希望能够过滤掉增量并更新条形图,因此“结果”需要更改,以便总和仍然是该粒度的预测:

Type          Amount
---------   ---------
Result         +900
Delta 1        +100

我们可以在一个视图,但是我们必须为增量选择和取消选择的每种可能性生成一个结果,这似乎不是最佳的。

有没有办法在立方体中做到这一点?我们最好的猜测是某种 MDX 计算成员,但我们也对其他解决方案持开放态度。

谢谢!

更新1: 我看到的计算字段的问题是,它向多维数据集添加了一个成员(即一列),而我们真正需要做的是使用 UNION 添加行......但在多维数据集中。以下是一些伪 SQL 作为示例:

SELECT 
  Year,
  'Result' AS Type,
  SUM(Amount) AS Amount
FROM Table1
WHERE 1=1
  --AND Type 'Delta 2' 
GROUP BY Year

UNION ALL

SELECT 
  Year,
  Type,
  -1*Amount AS Amount
FROM Table1
WHERE Type LIKE 'Delta%'
  --AND Type 'Delta 2'

--Note the commented out WHERE clauses are where you would de-select a delta if desired.

可以将其转换为 MDX 以进行即时计算吗?

更新2:

这是迄今为止我得到的最接近的结果,但它并不完美:

CREATE MEMBER CURRENTCUBE.[Measures].[Adjusted]
 AS CASE [Measure Type DEV].[Measure Type] /* This is the 'Type' column above */
    WHEN [Measure Type DEV].[Measure Type].&[2] /* Forecast is key 2 */
    THEN ([Measure Type DEV].[Measure Type].&[2],
        [Time].[Year].CURRENTMEMBER,[Measures].[Amount]) 
      + ([Measure Type DEV].[Measure Type].&[3], /* Delta is key 3 */
         [Time].[Year].CURRENTMEMBER,[Measures].[Amount]) END

We use a cube built in SSAS and we would like to show the effect of deltas against a forecast.

So, we have data like this:

Year    Type        Amount
----    ---------   ---------
2008    Forecast    +1000
2008    Delta 1     - 100
2008    Delta 2     - 200
2009    ...

We would like to make a stacked bar chart, so we need data like this:

Year    Type        Amount
----    ---------   ---------
2008    Result      +700
2008    Delta 1     +100
2008    Delta 2     +200

You can see that 'Result' equals the sum of forecast and the deltas, at a particular granularity (in this this example case it is just time, we will also have place as an added dimension).

The catch is we'd like to be able to filter out a delta and have the bar chart update, so then 'Result' would need to then to change so that the sum is still the forecast for that granularity:

Type          Amount
---------   ---------
Result         +900
Delta 1        +100

We could do this in a view, but then we'd have to generate a result for every possibility of delta selects and deselects, which doesn't seem optimal.

Is there a way to do this in the cube? Our best guess is some kind of MDX calculated member but we are open to other solutions as well.

Thanks!

UPDATE 1:
The problem I see with a calculated field is that it adds a member (i.e. a column) to the cube, where what we really need to do is add rows with a UNION...but in a cube. Here's some psuedo SQL as an example:

SELECT 
  Year,
  'Result' AS Type,
  SUM(Amount) AS Amount
FROM Table1
WHERE 1=1
  --AND Type 'Delta 2' 
GROUP BY Year

UNION ALL

SELECT 
  Year,
  Type,
  -1*Amount AS Amount
FROM Table1
WHERE Type LIKE 'Delta%'
  --AND Type 'Delta 2'

--Note the commented out WHERE clauses are where you would de-select a delta if desired.

Can that be translated to MDX for an on the fly calculation?

UPDATE 2:

This is the closest I've gotten so far, but it's not perfect:

CREATE MEMBER CURRENTCUBE.[Measures].[Adjusted]
 AS CASE [Measure Type DEV].[Measure Type] /* This is the 'Type' column above */
    WHEN [Measure Type DEV].[Measure Type].&[2] /* Forecast is key 2 */
    THEN ([Measure Type DEV].[Measure Type].&[2],
        [Time].[Year].CURRENTMEMBER,[Measures].[Amount]) 
      + ([Measure Type DEV].[Measure Type].&[3], /* Delta is key 3 */
         [Time].[Year].CURRENTMEMBER,[Measures].[Amount]) END

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

虐人心 2024-09-13 17:26:57

MDX 中没有真正的好方法来做到这一点,但当我必须创建预测时,我使用数据挖掘来完成此任务,并以本文作为我的主要参考点:

http://cwebbbi.spaces.live.com/Blog/cns!7B84B0F2C239489A!2795.entry?a665aac0& ;wa=wsignin1.0

我希望这会有所帮助,并且它可能比尝试直接使用 MDX 解决它更快。

There is no real great way in MDX to do this but when I had to create forcasts I used data mining to accomplish this task with this article as my main referencing point:

http://cwebbbi.spaces.live.com/Blog/cns!7B84B0F2C239489A!2795.entry?a665aac0&wa=wsignin1.0

I hope this helps and it may be quicker than attempting to solve it with straight MDX.

素染倾城色 2024-09-13 17:26:57

在我对问题的最后更新(更新2)中,我问如何在MDX中执行类似SQL的联合...这引导我走向正确的方向,但思考它的方式是错误的(我对MDX还是新手) 。

要添加结果“行”,我需要添加一个计算维度(可以放在行上),它返回所有级别,它执行我正在寻找的求和,并且我需要添加一个新的计算维度来执行case 语句(翻转一种情况下的减少量,从另一种情况下的总数中减去减少量)。

In my last update to the question (Update 2) I asked how to do a SQL like union in MDX...which led me in the right direction but is the wrong way of thinking about it (I'm still new to MDX).

To add that Result 'Row' I needed to add a calculated dimension (which can be put ON ROWS), that returned the All level, which does the summation I was looking for, AND I needed to add a new calculated dimension that would do the case statement (flip the reductions in one case, subtract the reductions from the total in the other).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文