0

I'm new to MDX and trying to solve the following problem. Investigated calculated members, subselects, scope statements, etc but can't quite get it to do what I want.

Let's say I'm trying to come up with the MDX equivalent to the following SQL query:

SELECT SUM(netMarketValue) net, 
  SUM(CASE WHEN netMarketValue > 0 THEN netMarketValue ELSE 0 END) assets,
  SUM(CASE WHEN netMarketValue < 0 THEN netMarketValue ELSE 0 END) liabilities,
  SUM(ABS(netMarketValue)) gross
  someEntity1
FROM (
SELECT SUM(marketValue) netMarketValue, someEntity1, someEntity2
FROM <some set of tables>
GROUP BY someEntity1, someEntity2) t
GROUP BY someEntity1

In other words, I have an account ledger where I hide internal offsetting transactions (within someEntity2), then calculate assets & liabilities after aggregating them by someEntity2. Then I want to see the grand total of those assets & liabilities aggregated by the bigger entity, someEntity1.

In my MDX schema I'd presumably have a cube with dimensions for someEntity1 & someEntity2, and marketValue would be my fact table/measure. I suppose i could create another DSV that did what my subquery does (calculating net), and simply create a cube with that as my measure dimension, but I wonder if there is a better way. I'd rather not have 2 cubes (one for these net calculations and another to go to a lower level of granularity for other use cases), since it will be a lot of duplicate info in my database. These will be very large cubes.

4

2 回答 2

0

我认为您应该将聚合逻辑留给多维数据集——这是它最擅长的。

在您的情况下,我将创建一个帐户维度,然后添加 Account Intelligence。但是,这仅适用于 SQL Server 企业版(2005 及更高版本)。

如果您碰巧拥有标准版,那么执行此操作的规范方法是使用一元运算符

这就是我们过去使用 Sql Server 2000 的方式,这里有一个很好的例子。

于 2009-02-27T19:07:46.353 回答
0

我认为您想要的不是两个多维数据集,而是一个带有两个事实表的多维数据集(有时称为星座模式)。这个问题是几个月前写的,所以除非有人要求更多信息,否则我不会在这里详细说明。

于 2009-10-13T15:03:23.243 回答