我正在尝试创建一个计算成员,该成员应该返回每人每周的平均订单。
以下是客户端希望预测工作量的屏幕截图。工作人员可能无法在一周内全天工作。
计算将是:该周的预定天数的订单/否。
如果周名称在日期的同一层次结构中,则计算这个并不是很难,但在这种情况下,它不在层次结构中,而只是维度的成员。
这是我尝试过的MDX:
import io
from django.test import TestCase
from django.template.engine import Engine
from core.loader import CustomLoader as BaseLoader # this is your custom template loader you want to test
class HelperLoader(BaseLoader):
is_usable = True
def load_template_source(self, template_name, template_dirs=None):
out_source, path = super(HelperLoader, self).load_template_source(template_name, template_dirs=None)
self.out_source = out_source
return out_source, path
class CustomLoaderTest(TestCase):
def test_custom_loader(self):
template_path = 'index.html'
engine = Engine()
engine.dirs = ['core/templates',] # `core/templates` is where your test template_path is located.
out = HelperLoader(engine)
template = out.load_template(template_path )
self.assertEqual('template source with updated content.', out.out_source)
答案 0 :(得分:0)
如果您将星期和日期添加到层次结构中会更容易,但如果您没有可能添加此功能,则会有不同的非优雅解决方案。
这只能在行上使用数周才能正常工作 - 所以我建议按周和日扩展您的日历层次结构,然后我们可以聊聊更优雅的解决方案。
答案 1 :(得分:0)
尝试使用:
WITH MEMBER [Measures].[avg_week] AS
Avg ( EXISTING { [Date Planned].[Week Of Year].[Week Of Year] },
[Measures].[Orders Qty] )
SELECT [Measures].[avg_week] ON COLUMNS,
NON EMPTY
{ [Person].[PersonName].[PersonName] * [Date Planned].[Week Of Year].[Week Of Year] } ON ROWS
FROM [Your cube]
请告诉我这是否可以帮助您。
答案 2 :(得分:0)
可能类似以下内容:
WITH
MEMBER [Measures].[PlannedDayCnt] AS
Count
(
Exists
(
(EXISTING
[Date Planned].[Date Planned].[Date Planned].MEMBERS)
,[Date Planned].[Week Of Year].currentmember
)
)
MEMBER [Measures].[Averge Orders] AS
[Measures].[Orders Qty] / [Measures].[PlannedDayCnt]
SELECT
{
[Measures].[Orders Qty]
,[Measures].[PlannedDayCnt]
,[Measures].[Averge Orders]
} ON 0
,
[Person].[PersonName].[PersonName]
* [Date Planned].[Week Of Year].[Week Of Year] ON 1
FROM [aCube];
我想测试但不确定如何在AdvWrks
多维数据集中为您的方案建模。
答案 3 :(得分:0)
我首先要查看本周有多少“日期”。这很容易,因为在那个星期订单被安排给那个人的那些日子。
NonEmpty
(
[Date Planned].[Date Planned].[Date Planned].MEMBERS,
(
[Date Planned].[Week Of Year].currentmember,
[Person].[PersonName].currentmember,
[Measures].[Orders Qty]
)
)
现在您已拥有“当前”周和“当前”人员的必需日期,您需要计算这些日期的平均订单数量。它看起来像这样:
AVG
(
NonEmpty
(
[Date Planned].[Date Planned].[Date Planned].MEMBERS,
(
[Date Planned].[Week Of Year].currentmember,
[Person].[PersonName].currentmember,
[Measures].[Orders Qty]
)
)
, [Measures].[Orders Qty]
)
您的最终构造需要:
WITH MEMBER Measures.AverageOrderPerDay AS
AVG
(
NonEmpty
(
[Date Planned].[Date Planned].[Date Planned].MEMBERS,
(
[Date Planned].[Week Of Year].currentmember,
[Person].[PersonName].currentmember,
[Measures].[Orders Qty]
)
)
, [Measures].[Orders Qty]
)
SELECT
{
[Measures].AverageOrderPerDay,
[Measures].[Orders Qty]
}
ON 0,
[Person].[PersonName].[PersonName].MEMBERS
* [Date Planned].[Week Of Year].[Week Of Year].MEMBERS ON 1
FROM [YourCube]