简体   繁体   English

如何在另一个层次结构中执行MDX成员减法?

[英]How do I perform MDX member subtraction across another hierarchy?

I have a cube with customers and products. 我有一个与客户和产品有关的多维数据集。 Each customer holds a varying combination of products, each in different amounts. 每个客户持有不同数量的产品组合。

I would like to calculate the difference (subtraction), between one customer and another, of amounts held in each product. 我想计算一个客户与另一个客户在每种产品中持有的金额之间的差异(相减)。

I am using SQL Server Analysis Services 2014. An example from AdventureWorksDW2014 would be: 我正在使用SQL Server Analysis Services2014。AdventureWorksDW2014的示例为:

select
{[Customer].[Country].&[Australia],[Customer].[Country].&[Canada]} on columns,
non empty ([Product].[Category].members, [Measures].[Internet Sales Amount]) on rows
from 
[Adventure Works]

This generates the following output: 这将产生以下输出:

                Australia       Canada
All Products    $9,061,000.58   $1,977,844.86
Accessories     $138,690.63     $103,377.85
Bikes           $8,852,050.00   $1,821,302.39
Clothing        $70,259.95      $53,164.62

However what I would like to obtain is 但是我想得到的是

                Australia       Canada          (Australia - Canada)
All Products    $9,061,000.58   $1,977,844.86   $7,083,155.72
Accessories     $138,690.63     $103,377.85     $35,312.78
Bikes           $8,852,050.00   $1,821,302.39   $7,030,747.61
Clothing        $70,259.95      $53,164.62      $17,095.33

Ideally this could be performed not just in MDX, but allowing the user to select any two arbitrary customers for comparison. 理想情况下,不仅可以在MDX中执行此操作,还可以允许用户选择任意两个任意客户进行比较。

This is my first MDX question, so please let me know if it should be framed differently. 这是我的第一个MDX问题,所以请让我知道是否应采用不同的框架。

Here is the MDX query for the desired output: 这是所需输出的MDX查询:

WITH MEMBER Australia AS
SUM({([Measures].[Internet Sales Amount], [Customer].[Country].&[Australia])}), FORMAT_STRING = "#,#.##"
MEMBER Canada AS
SUM({([Measures].[Internet Sales Amount], [Customer].[Country].&[Canada])}), FORMAT_STRING = "#,#.##"
MEMBER [Australia - Canada] AS
[Australia] - [Canada]
SELECT
{[Australia], [Canada], [Australia - Canada]} ON COLUMNS,
NON EMPTY {[Product].[Category].MEMBERS} ON ROWS
FROM [Adventure Works]

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

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