我需要一个很大的帮助。
我正在使用MDX在Pentaho中生成图形 - CDE / CTools。我需要做一系列由用户设置的过滤器。图表是每日进度,我想添加月份的平均线。但它运作得不好。
我做错了什么?我对MDX知之甚少。它应该显示值并重复整个月的平均值,但它重复相同的值。
WITH
MEMBER [Measures].[AVG] AS
AVG ([MONTH].[MONTH].CurrentMember, [Measures].[QTD])
SELECT NON EMPTY {[Measures].[QTD], [Measures].[AVG]} ON COLUMNS,
{[DATE].[DATE].Members} ON ROWS
FROM [DW20_DAY]
WHERE Crossjoin(Crossjoin(Crossjoin({[MONTH].[All MONTHs]}, {[CAUSE].[All CAUSEs]}), {[TYPE].[All TYPEs]}), {[MODEL].[All MODELs]})
使用过滤器:
WITH
MEMBER [Measures].[AVG] AS
AVG ([MONTH].[MONTH].CurrentMember, [Measures].[QTD])
SELECT NON EMPTY {[Measures].[QTD], [Measures].[AVG]} ON COLUMNS,
{[DATE].[DATE].Members} ON ROWS
FROM [DW20_DAY]
WHERE Crossjoin(Crossjoin(Crossjoin({[MONTH].[2017-03-01]}, {[CAUSE].[All CAUSEs]}), {[TYPE].[All TYPEs]}), {[MODEL].[All MODELs]})
数据样本 - 在这种情况下,平均值应为:7.567.743
DATE QTD AVERAGE It has to be
01/11/2016 7.731.442 7.731.442 7.567.743
02/11/2016 7.973.846 7.973.846 7.567.743
03/11/2016 7.430.333 7.430.333 7.567.743
04/11/2016 7.517.061 7.517.061 7.567.743
05/11/2016 6.738.677 6.738.677 7.567.743
06/11/2016 6.796.424 6.796.424 7.567.743
07/11/2016 7.631.584 7.631.584 7.567.743
08/11/2016 7.907.649 7.907.649 7.567.743
09/11/2016 8.995.933 8.995.933 7.567.743
10/11/2016 7.444.471 7.444.471 7.567.743
11/11/2016 8.039.431 8.039.431 7.567.743
12/11/2016 7.240.583 7.240.583 7.567.743
13/11/2016 6.779.103 6.779.103 7.567.743
14/11/2016 7.648.149 7.648.149 7.567.743
15/11/2016 7.641.452 7.641.452 7.567.743
---- 编辑:
我要求创建时间维度。 现在它处于同一层次结构中。
但我仍然无法解决它。 在这种情况下,它看起来怎么样?
WITH MEMBER [Measures].[AVG] AS
Avg( Descendants([TIME].[MONTH].CURRENTMEMBER, [TIME].[DATE])
, [Measures].[QTDE]
)
SELECT {[Measures].[QTD], [Measures].[AVG]} ON COLUMNS,
NON EMPTY{[TIME].[DATE].MEMBERS} ON ROWS
FROM [DW20_DAY]
感谢。
答案 0 :(得分:1)
如果您在日期维度中有多级用户层次结构但是您使用以下两个属性层次结构,则可以轻松完成此类查询:
[MONTH].[MONTH]
[DATE].[DATE]
尝试对Date使用currentmember,然后使用NonEmpty来获取相应的月份:
NonEmpty([MONTH].[MONTH].MEMBERS,[DATE].CURRENTMEMBER)
然后你需要找到与该月相关的日期来做平均值:
NonEmpty([DATE].[DATE].MEMBERS,
NonEmpty([MONTH].[MONTH].MEMBERS,[DATE].CURRENTMEMBER).ITEM(0)
)
然后尝试应用平均值:
WITH
MEMBER [Measures].[AVG] AS
AVG (
NonEmpty(
[DATE].[DATE].MEMBERS,
NonEmpty(
[MONTH].[MONTH].MEMBERS,[DATE].CURRENTMEMBER).ITEM(0)
)
, [Measures].[QTD]
)
...
...
我需要针对AdvWrks进行上述测试!
答案 1 :(得分:0)
以下代码也必须正常运行:
Member [Measures].[AVG] as
AVG([DATE].[DATE].[DATE].Members, [Measures].[QTD])
如果您有等级日 - >一个月,想要通过父母获得AVG,请尝试:
AVG([DATE].[DATE].CurrentMember.Siblings, [Measures].[QTD])