我有一个复杂的MDX计算度量问题。我有两个度量和一个小时分钟层次结构。在每小时一级,MeasureA会累积到基础分钟值的最大值。 MeasureB应该从MeasureA累积到Max的相应值。在下面的示例中,8是最大测量值A.因此,MeasureB应该在每小时水平上升到2。我在使用MeasureB计算时遇到问题。任何想法如何在MDX计算的度量中做到这一点?
MeasureA Measure B
Hour 8 2
Minute1 2 3
Minute2 1 2
Minute3 5 1
Minute4 6 3
Minute5 8 2
除了以上......我有两个层次结构"年 - 月 - 日"和"小时分钟"。这适用于小时分钟层次。但是,当我也想要相同的逻辑从一小时到另一天卷起来,即使它们在不同的层次结构中。我有下面的代码用于工作时/分钟键和非工作日键。你看到我做错了什么。
衡量A ="平均使用资源"和措施B ="总资源"
// Total Resources Calculation
---Initializing keys
CREATE MEMBER CURRENTCUBE.[Measures].[Avg Used Resources Key Minutes]
AS null,
VISIBLE = 1, ASSOCIATED_MEASURE_GROUP = 'NSS Resource Utilization';
CREATE MEMBER CURRENTCUBE.[Measures].[Avg Used Resources Key Hours]
AS null,
VISIBLE = 1, ASSOCIATED_MEASURE_GROUP = 'NSS Resource Utilization';
CREATE MEMBER CURRENTCUBE.[Measures].[Avg Used Resources Key Days]
AS null,
VISIBLE = 1, ASSOCIATED_MEASURE_GROUP = 'NSS Resource Utilization';
---
-- Minute Key
SCOPE ([Time].[Hour-Minute].[Time Name],[Measures].[Avg Used Resources Key Minutes]);
THIS = IIF(([Time].[Hour-Minute].CurrentMember,[Measures].[Avg Used Resources])
= ([Time].[Hour-Minute].CurrentMember.Parent,[Measures]. [Avg Used Resources])
, [Time].[Hour-Minute].CurrentMember.Member_Key, null);
END SCOPE;
-- Hour Key
SCOPE ([Measures].[Avg Used Resources Key Hours]);
THIS = MAX([Time].[Hour-Minute].CurrentMember.Children,[Measures].[Avg Used Resources Key Minutes]);
END SCOPE;
-- Day Key
SCOPE ([Measures].[Avg Used Resources Key Days]);
THIS = IIF(([Time].[Hour-Minute].CurrentMember,[Measures].[Avg Used Resources])
= ([Time].[Hour-Minute].CurrentMember.Parent, [Measures].[Avg Used Resources])
, [Time].[Hour-Minute].CurrentMember.Member_Key, null);
END SCOPE;
-- Hour Value
SCOPE ([Time].[Hour-Minute].[Hour 24],[Measures].[Total Resources]);
THIS = (StrToMember("[Time].[Hour-Minute].[Time Name].&["+CStr([Measures]. [Avg Used Resources Key Hours])+"]")
,[Measures].[Total Resources]);
END SCOPE;
--Date Value
SCOPE ([Time].[Hour-Minute].[ALL],[Measures].[Total Resources]);
THIS = (StrToMember("[Time].[Hour-Minute].[Hour 24].&["+CStr([Measures].[Avg Used Resources Key Days])+"]")
,[Measures].[Total Resources]);
END SCOPE;
答案 0 :(得分:0)
我有非常愚蠢的解决方案,但它有效!主要思想是将必要的分钟成员的密钥发送到小时级别。
创建额外的空度量来存储最大分钟值的键:
CREATE MEMBER CURRENTCUBE.[Measures].[Measure A Key Minutes]
AS null,
VISIBLE = 0;
CREATE MEMBER CURRENTCUBE.[Measures].[Measure A Key Hours]
AS null,
VISIBLE = 0;
比添加范围来计算它们:
SCOPE ([Date].[Date].[Minutes],[Measures].[Measure A Key Minutes]);
THIS = IIF(([Date].[Date].CurrentMember,[Measures].[Measure A]) = ([Date].[Date].CurrentMember.Parent,[Measures].[Measure A])
, [Date].[Date].CurrentMember.Member_Key, null);
END SCOPE;
SCOPE ([Measures].[Measure A Key Hours]);
THIS = MAX([Date].[Date].CurrentMember.Children,[Measures].[Measure A Key Minutes]);
END SCOPE;
如果分钟级别的值等于小时级别,则第一个范围将成员的键放入新度量。第二个将此值移动到小时级别。现在我们在小时级别上有最大分钟值的键。
然后添加最后一个范围来更新测量B:
SCOPE ([Date].[Date].[Hours],[Measures].[Measure B]);
THIS = (StrToMember("[Date].[Date].&["+CStr([Measures].[Measure A Key Hours])+"]")
,[Measures].[Measure B]);
END SCOPE;
这对于大尺寸来说绝对是缓慢的解决方案(服务器肯定会切换到逐个单元格模式!),它是严格而严格的,但是......它的工作原理。刚刚测试过。
欢迎任何增加如何加速。但最好还是采用另一种方法。
更新:(由于bug而被重新编辑) 不幸的是,没有简单的方法来添加新的水平。但你可以这样做:
不幸的是,这是一个可用的解决方案。
因此,第一个衡量标准就像“分钟级别的分钟键”,第二个衡量标准是“小时级别的分钟键”。比你需要添加“小时级别的小时键”和“天级别的小时键”等措施,以及日级别的另一个范围。
CREATE MEMBER CURRENTCUBE.[Measures].[Measure A Key Hour - Hour Level]
AS null,
VISIBLE = 0;
CREATE MEMBER CURRENTCUBE.[Measures].[Measure A Key Hour - Day Level]
AS null,
VISIBLE = 0;
SCOPE ([Date].[Date].[Hour],[Measures].[Measure A Key Hour - Hour Level]);
THIS = IIF(([Date].[Date].CurrentMember,[Measures].[Measure A]) = ([Date].[Date].CurrentMember.Parent,[Measures].[Measure A])
, [Date].[Date].CurrentMember.Member_Key, null);
END SCOPE;
SCOPE ([Date].[Date].[Day],[Measures].[Measure A Key Hour - Day Level]);
THIS = MAX([Date].[Date].CurrentMember.Children,[Measures].[Measure A Key Hour - Hour Level]);
END SCOPE;
SCOPE ([Date].[Date].[Day],[Measures].[Measure B]);
THIS = (StrToMember("[Date].[Date].&["+CStr([Measures].[Measure A Key Hour - Day Level])+"]")
,[Measures].[Measure B]);
END SCOPE;
我相信你的第一个衡量标准的逻辑是每小时的最大值数天或像这样的数字。