我使用MDX
代码来计算四分位数,就像在这个博客中一样:
https://electrovoid.wordpress.com/2011/06/24/ssas-quartile/
这就是我在做的事情:
WITH SET OrderedData AS
ORDER
(
NONEMPTY
(
[Dim Parameter].[id].[id]
*[Dim Result].[Id].[Id].ALLMEMBERS,
[Measures].[Value]
),
[Measures].[Value],
BASC
)
MEMBER [Measures].[RowCount] AS COUNT (OrderedData)
MEMBER [Measures].[i25] AS ( .25 * ( [RowCount] - 1 ) ) + 1
MEMBER [Measures].[i25Lo] AS FIX([i25]) - 1
MEMBER [Measures].[i25Rem] AS ([i25] - FIX([i25]))
MEMBER [Measures].[n25Lo] AS (OrderedData.Item([i25Lo]), [Value])
MEMBER [Measures].[n25Hi] AS (OrderedData.Item([i25Lo] + 1), [Value])
MEMBER [Measures].[Quartile1] AS [n25Lo] + ( [i25Rem] * ( [n25Hi] - [n25Lo] ))
,FORMAT_STRING='Currency'
MEMBER [Measures].[Quartile2] AS MEDIAN(OrderedData, [Value])
,FORMAT_STRING='Currency'
MEMBER [Measures].[i75] AS ( .75 * ( [RowCount] - 1 ) ) + 1
MEMBER [Measures].[i75Lo] AS FIX([i75]) - 1
MEMBER [Measures].[i75Rem] AS ([i75] - FIX([i75]))
MEMBER [Measures].[n75Lo] AS (OrderedData.Item([i75Lo] ),[Value])
MEMBER [Measures].[n75Hi] AS (OrderedData.Item([i75Lo] + 1),[Value])
MEMBER [Measures].[Quartile3] AS [n75Lo] + ( [i75Rem] * ( [n75Hi] - [n75Lo] ))
,FORMAT_STRING='Currency'
MEMBER [Measures].[RIC] As ([Quartile3]-[Quartile1] )
MEMBER [Measures].[Ls] As ([Quartile3]+ ([RIC]*1.5) )
MEMBER [Measures].[Li] As ([Quartile1]- ([RIC] *1.5))
MEMBER [Measures].[MAX] as MAX (Filter(OrderedData ,[value]<=[LS]),[value])
MEMBER [Measures].[Min] as MIn(Filter(OrderedData ,[value]>=[Li]),[value])
MEMBER [Measures].[out] as MAX (Filter(OrderedData ,[value]>[LS]),[value
我想要的是添加Dim日期,计算每个月的四分位数,如下所示:
MEMBER [Measures].[out] as MAX (Filter(OrderedData ,[value]>[LS]),[value
SELECT {
[Measures].[Quartile1],[Measures].[Quartile2],[Measures].[Quartile3], [min],
[MAX] , [out] , [Measures].[ValueAVG],[RowCount],[Measures].[Recuento Fact Result]
} ON 0 ,
[Dim Parameter].[Reference].[Reference] *
[Dim Parameter].[Section ES].[Section ES] *
[Id Distribution Date].[DateJ].[Month] ON 1
FROM [Tess Tek DW Dev]
但是它不起作用,如何只在一个mdx
查询中计算不同日期范围的四分位数?
答案 0 :(得分:0)
您需要以某种方式将日期纳入WITH
语句。
首先尝试将目标月份(将在行上)添加到命名集合中:
WITH
SET [TargetSet] AS
{
[Id Distribution Date].[DateJ].[Month].[Jan-2015],
[Id Distribution Date].[DateJ].[Month].[Feb-2015]
}
然后我会添加另一个将TargetSet考虑在内的集合:
SET [NonEmptyIds] AS
NonEmpty(
[Dim Parameter].[id].[id]
*[Dim Result].[Id].[Id].ALLMEMBERS
,
{[Measures].[Value]} * [TargetSet]
)
然后将此集合提供给您当前的集合:
SET [OrderedData] AS
ORDER
(
[NonEmptyIds],
[Measures].[Value],
BASC
)
然后尝试修改行代码段以使用TargetSet:
[Dim Parameter].[Reference].[Reference] *
[Dim Parameter].[Section ES].[Section ES] *
[TargetSet] ON 1