MDX: avg advanced use

杀马特。学长 韩版系。学妹 提交于 2019-12-24 07:14:09

问题


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,


回答1:


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).




回答2:


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])}


来源:https://stackoverflow.com/questions/6175962/mdx-avg-advanced-use

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!