MDX:平均高级使用

发布于 2024-11-10 18:30:14 字数 2015 浏览 3 评论 0原文

我在一个问题上已经达到了我的基本 MDX 知识的极限,如果有人有想法,欢迎提供帮助

情况

这是我想要处理的层次结构。在我的fact_table 中,我有一个[Measures].[Sales] 度量。

[All Management].[TemplateMgt].[CityMgt].[DistricMgt].[StoreMgt]

[All Management].[TMP-00.002].[London].[DistricMgt].[Shoe001]
[All Management].[TMP-00.002].[London].[DistricMgt].[Hat001]
[All Management].[TMP-00.002].[London].[DistricMgt].[Electronic001]
[All Management].[TMP-00.002].[Paris].[DistricMgt].[Shoe001]
[All Management].[TMP-00.002].[Paris].[DistricMgt].[Hat001]
[All Management].[TMP-00.002].[Paris].[DistricMgt].[Electronic001]
[All Management].[TMP-00.002].[Madrid].[DistricMgt].[Shoe001]
[All Management].[TMP-00.002].[Madrid].[DistricMgt].[Hat001]
[All Management].[TMP-00.002].[Madrid].[DistricMgt].[Electronic001]

问题

对于给定的 CityMgt,我想要三个值

[Measures].[Cur]: StoreMgt 给定 CityMgt 的销售额(因此对于马德里,获取值 [ Shoe001]、[Hat001]、[Electronic001])

[Measures].[Avg]:具有相同条件的 StoreMgt 组的 StoreMgt 的平均销售额TemplateMgt AVG([伦敦].[Shoe001] + [巴黎].[Shoe001] + [马德里].[Shoe001])

[Measures].[Max]: StroreMgt 的最大销售额相同的 TemplateMgt MAX([伦敦].[Shoe001], [巴黎].[Shoe001], [Madrid].[Shoe001])

换句话说,我想要一个具有这种结构的输出

  Shoe001    |  Hat001     |  Electronic001
 ----------------------------------------------------
 CUR|AVG|MAX | CUR|AVG|MAX  | CUR|AVG|MAX
 ----------------------------------------------------

到目前为止我得到了什么

WITH  MEMBER [Measures].[Cur] AS (...)
          MEMBER [Measures].[Avg] AS (...)
          MEMBER [Measures].[Max] AS (...)

SELECT {[Measures].[Cur], [Measures].[Avg], [Measures].[Max]} ON COLUMNS,
{FILTER({DESCENDANTS([All Management].CurrentMember, [StoreMgt])}, [All Management].Parent.Parent = "Madrid" } ON ROWS
from [MyCube]

我的问题是我不知道要放入什么成员属性 Cur/Avg/Max,这样我的数据就可以按 StoreMgt(一种 gr​​oupby)进行处理。

如果有人可以启发我,我将不胜感激。

诚挚地,

I am reaching the limit of my basic MDX knowledge on a problem, if anyone has an idea, every help will be welcome

Situation

This is the hierarchy I'd like to deal with. In my fact_table I have a [Measures].[Sales] measure.

[All Management].[TemplateMgt].[CityMgt].[DistricMgt].[StoreMgt]

[All Management].[TMP-00.002].[London].[DistricMgt].[Shoe001]
[All Management].[TMP-00.002].[London].[DistricMgt].[Hat001]
[All Management].[TMP-00.002].[London].[DistricMgt].[Electronic001]
[All Management].[TMP-00.002].[Paris].[DistricMgt].[Shoe001]
[All Management].[TMP-00.002].[Paris].[DistricMgt].[Hat001]
[All Management].[TMP-00.002].[Paris].[DistricMgt].[Electronic001]
[All Management].[TMP-00.002].[Madrid].[DistricMgt].[Shoe001]
[All Management].[TMP-00.002].[Madrid].[DistricMgt].[Hat001]
[All Management].[TMP-00.002].[Madrid].[DistricMgt].[Electronic001]

Problem

For a given CityMgt, I would like to have three values

[Measures].[Cur]: StoreMgt's sales of the given CityMgt (So for Madrid, get the value [Shoe001], [Hat001], [Electronic001])

[Measures].[Avg]: the average sales of StoreMgt group by StoreMgt having the same TemplateMgt AVG([London].[Shoe001] + [Paris].[Shoe001] + [Madrid].[Shoe001])

[Measures].[Max]: the max sales values of StroreMgt having the same TemplateMgt MAX([London].[Shoe001], [Paris].[Shoe001], [Madrid].[Shoe001])

In other word, I'd like to have an output that will have this structure

  Shoe001    |  Hat001     |  Electronic001
 ----------------------------------------------------
 CUR|AVG|MAX | CUR|AVG|MAX  | CUR|AVG|MAX
 ----------------------------------------------------

What I got so far

WITH  MEMBER [Measures].[Cur] AS (...)
          MEMBER [Measures].[Avg] AS (...)
          MEMBER [Measures].[Max] AS (...)

SELECT {[Measures].[Cur], [Measures].[Avg], [Measures].[Max]} ON COLUMNS,
{FILTER({DESCENDANTS([All Management].CurrentMember, [StoreMgt])}, [All Management].Parent.Parent = "Madrid" } ON ROWS
from [MyCube]

My problem is that I don't know what to put in the Member attributes Cur/Avg/Max so my datas can be treated per StoreMgt (a kind of groupby)

If anyone can enligthenme, I will appreciate.

Cordially,

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

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

发布评论

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

评论(2

最冷一天 2024-11-17 18:30:14

要获得平均值,您可以定义新的层次结构(如果您使用 SSAS,则为属性)。一个用于国家/地区,另一个用于产品类型。一旦你得到它们,统计计算就是与当前成员和[全部]一起玩的问题。

您可以选择其他版本 -> SUM( FILTER(..members, condition), value)...这可能很慢,非常慢。

一般来说,对于这种计算,您可以使用我们所说的统计或实用维度(

To get the average you can define new hierarchies (attributes if you're on SSAS). One for the country and another for the product type. Once you get them the statistical calculations are a question of playing with the currentmember and the [All].

You can go for another version -> SUM( FILTER(..members, condition), value)... this can be slow, really slow.

In general, for this kind of calculation you can use what we call statistical or utility dimensions (see).

她比我温柔 2024-11-17 18:30:14

我不完全确定以下查询是否有效,希望它传达了这个想法,

WITH MEMBER [All Management].[Sales_AVG] AS AVG({[All Management].Members},                           
                                                       [Measures].currentMember)
     MEMBER [All Management].[Sales_MAX] AS MAX({[All Management].Members},        
                                                        [Measure].currentMember)
SELECT {[Measures].[Sales]} ON COLUMNS,
       {[All Management].Members, [All Management].[Sales_AVG], 
         [All Management].[sales_Max]} ON ROWS FROM [MYCUBE] WHERE
       {DESCENDANTS([All Management].CurrentMember, [StoreMgt])}

I am not completely sure that following query will work, hope it conveys the idea,

WITH MEMBER [All Management].[Sales_AVG] AS AVG({[All Management].Members},                           
                                                       [Measures].currentMember)
     MEMBER [All Management].[Sales_MAX] AS MAX({[All Management].Members},        
                                                        [Measure].currentMember)
SELECT {[Measures].[Sales]} ON COLUMNS,
       {[All Management].Members, [All Management].[Sales_AVG], 
         [All Management].[sales_Max]} ON ROWS FROM [MYCUBE] WHERE
       {DESCENDANTS([All Management].CurrentMember, [StoreMgt])}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文