"Same Store" 使用 MDX 计算
"Same Store" calculations with MDX
我是 MDX 新手,在 google 上找不到这个。
我正在尝试获取一组一致记录(不包括在此期间添加或删除的任何记录)随时间变化的平均价格。
我已经尝试了一些方法,但总是碰壁,这是我最近的尝试,结果是“检测到#Error Infinite recursion。依赖循环是:Avg Monthly Price (Same Store) -> Avg Monthly Price (同一家商店)。
WITH
// Period Data
MEMBER [Date].[Date Id].PeriodCount AS
COUNT([Date].[Period].&[2018-01-01T00:00:00] : [Date].[Period].&[2018-12-01T00:00:00])
MEMBER [Date].[Date Id].NonEmptyPeriodCount AS
COUNT(
NonEmpty(
[Date].[Period].&[2018-01-01T00:00:00] : [Date].[Period].&[2018-12-01T00:00:00],
[Measures].[Monthly Price]
)
)
// Calculations
MEMBER Measures.[Avg Monthly Price] AS [Measures].[Monthly Price] / [Measures].[Fact Monthly Price History Count]
MEMBER Measures.[Avg Monthly Price (Same Store)] AS
AGGREGATE(
FILTER(
[Product].[Product Id].MEMBERS,
[Date].[Date Id].NonEmptyPeriodCount = [Date].[Date Id].PeriodCount
),
[Measures].[Monthly Price]
)
SELECT
NON EMPTY {
[Measures].[Avg Monthly Price],
[Measures].[Avg Monthly Price (Same Store)]
} ON COLUMNS,
NON EMPTY (
[Date].[Period].Children
) ON ROWS
FROM
MyCube
WHERE
[Date].[Year].&[2018]
我觉得这应该比我做的容易得多...任何帮助将不胜感激。
编辑:
我试图用简单的方式解决的问题是获取每个日期的平均值,不包括在整个报告期间添加或删除的任何记录。
例如给定以下集合:
Record | 1/1/2019 | 2/1/2019 | 3/1/2019 | 4/1/2019 | 5/1/2019
1 | 9 | 10 | 11 | 12 | 13
2 | | | 22 | 23 | 24
3 | 10 | 11 | 12 | 13 | 14
4 | 20 | 21 | 22 | |
5 | 11 | 12 | 13 | 14 | 15
我想排除记录 2 和 4,因为它们在整个集合中都不存在,所以平均加班时间会受到添加或删除记录的影响。
对于上面的设置,我想 return:
Period | Avg.
1/1/2019 | 10
2/1/2019 | 11
3/1/2019 | 12
4/1/2019 | 13
5/1/2019 | 14
欢迎来到 MDX,
更改查询中前两个度量的层次结构
MEMBER [Date].[Date Id].PeriodCount
MEMBER [Date].[Date Id].NonEmptyPeriodCount
至
MEMBER [Measures].PeriodCount
MEMBER [Measures].NonEmptyPeriodCount
现在在最后一节中提到他们
[Measures].PeriodCount = [Measures].NonEmptyPeriodCount
我可以通过将 Period Count 度量添加到多维数据集中来实现此功能,然后使用聚合成员,我的最终结果如下所示:
WITH
MEMBER [Date].[Hierarchy].Dates AS
AGGREGATE({
[Date].[Hierarchy].[Period].&[2018-01-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-02-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-03-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-04-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-05-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-06-01T00:00:00]
})
MEMBER AvgMonthlyPrice AS
[Measures].[Monthly Price] / [Measures].[Monthly Price Count]
MEMBER [Location].[Location Id].ValidLocation AS
AGGREGATE(FILTER(EXISTING([Location].[Location Id].[Location Id]), ([Measures].[Period Count], [Date].[Hierarchy].Dates) = 6))
SELECT
{[Measures].[Monthly Price],[Measures].[Monthly Price Count], AvgMonthlyPrice, [Property Count]} ON COLUMNS,
[Date].[Period].[Period] ON ROWS
FROM
[MyCube]
WHERE
(
[Date].[Hierarchy].Dates,
[Market].[Market Id].&[300000],
[Location].[Location Id].ValidLocation
)
可能有更优雅的方法来执行此操作,但目前有效。
我是 MDX 新手,在 google 上找不到这个。
我正在尝试获取一组一致记录(不包括在此期间添加或删除的任何记录)随时间变化的平均价格。
我已经尝试了一些方法,但总是碰壁,这是我最近的尝试,结果是“检测到#Error Infinite recursion。依赖循环是:Avg Monthly Price (Same Store) -> Avg Monthly Price (同一家商店)。
WITH
// Period Data
MEMBER [Date].[Date Id].PeriodCount AS
COUNT([Date].[Period].&[2018-01-01T00:00:00] : [Date].[Period].&[2018-12-01T00:00:00])
MEMBER [Date].[Date Id].NonEmptyPeriodCount AS
COUNT(
NonEmpty(
[Date].[Period].&[2018-01-01T00:00:00] : [Date].[Period].&[2018-12-01T00:00:00],
[Measures].[Monthly Price]
)
)
// Calculations
MEMBER Measures.[Avg Monthly Price] AS [Measures].[Monthly Price] / [Measures].[Fact Monthly Price History Count]
MEMBER Measures.[Avg Monthly Price (Same Store)] AS
AGGREGATE(
FILTER(
[Product].[Product Id].MEMBERS,
[Date].[Date Id].NonEmptyPeriodCount = [Date].[Date Id].PeriodCount
),
[Measures].[Monthly Price]
)
SELECT
NON EMPTY {
[Measures].[Avg Monthly Price],
[Measures].[Avg Monthly Price (Same Store)]
} ON COLUMNS,
NON EMPTY (
[Date].[Period].Children
) ON ROWS
FROM
MyCube
WHERE
[Date].[Year].&[2018]
我觉得这应该比我做的容易得多...任何帮助将不胜感激。
编辑:
我试图用简单的方式解决的问题是获取每个日期的平均值,不包括在整个报告期间添加或删除的任何记录。
例如给定以下集合:
Record | 1/1/2019 | 2/1/2019 | 3/1/2019 | 4/1/2019 | 5/1/2019
1 | 9 | 10 | 11 | 12 | 13
2 | | | 22 | 23 | 24
3 | 10 | 11 | 12 | 13 | 14
4 | 20 | 21 | 22 | |
5 | 11 | 12 | 13 | 14 | 15
我想排除记录 2 和 4,因为它们在整个集合中都不存在,所以平均加班时间会受到添加或删除记录的影响。
对于上面的设置,我想 return:
Period | Avg.
1/1/2019 | 10
2/1/2019 | 11
3/1/2019 | 12
4/1/2019 | 13
5/1/2019 | 14
欢迎来到 MDX,
更改查询中前两个度量的层次结构
MEMBER [Date].[Date Id].PeriodCount
MEMBER [Date].[Date Id].NonEmptyPeriodCount
至
MEMBER [Measures].PeriodCount
MEMBER [Measures].NonEmptyPeriodCount
现在在最后一节中提到他们
[Measures].PeriodCount = [Measures].NonEmptyPeriodCount
我可以通过将 Period Count 度量添加到多维数据集中来实现此功能,然后使用聚合成员,我的最终结果如下所示:
WITH
MEMBER [Date].[Hierarchy].Dates AS
AGGREGATE({
[Date].[Hierarchy].[Period].&[2018-01-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-02-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-03-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-04-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-05-01T00:00:00],
[Date].[Hierarchy].[Period].&[2018-06-01T00:00:00]
})
MEMBER AvgMonthlyPrice AS
[Measures].[Monthly Price] / [Measures].[Monthly Price Count]
MEMBER [Location].[Location Id].ValidLocation AS
AGGREGATE(FILTER(EXISTING([Location].[Location Id].[Location Id]), ([Measures].[Period Count], [Date].[Hierarchy].Dates) = 6))
SELECT
{[Measures].[Monthly Price],[Measures].[Monthly Price Count], AvgMonthlyPrice, [Property Count]} ON COLUMNS,
[Date].[Period].[Period] ON ROWS
FROM
[MyCube]
WHERE
(
[Date].[Hierarchy].Dates,
[Market].[Market Id].&[300000],
[Location].[Location Id].ValidLocation
)
可能有更优雅的方法来执行此操作,但目前有效。