MDX:平均高级使用
我在一个问题上已经达到了我的基本 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(一种 groupby)进行处理。
如果有人可以启发我,我将不胜感激。
诚挚地,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获得平均值,您可以定义新的层次结构(如果您使用 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).
我不完全确定以下查询是否有效,希望它传达了这个想法,
I am not completely sure that following query will work, hope it conveys the idea,