SSAS - > KPI创建 - >如何创建一个比较前一天客户等级的kpi?

时间:2012-01-24 22:56:47

标签: sql-server sql-server-2012 ssas cube kpi

我一直致力于创建一个kpi,用于比较特定日期的客户与前一天的排名。反过来,您将能够看到该客户的排名是上升还是排名下降。在我的情况下,他们按收入排序。

我能够通过排名功能对我的客户进行足够的排名并提供报告,但是当创建比较这些排名的kpi时,我正在努力弄清楚应该如何处理这个问题。排名本身不是作为数据存储的东西,我需要通过排名函数动态创建。

以下是我用于创建初始启动报告的mdx查询示例,该报告为我提供了没有日期拼接的客户排名:

WITH SET [RevRank] AS
ORDER (
    [Customer].[Customer Id].CHILDREN ,
    [Measures].[Revenue], BDESC)  
  MEMBER [Measures].[RANKRevenue] AS RANK([Customer].[Customer Id].CurrentMember, [RevRank] )

SELECT NON EMPTY { [Measures].[Revenue], [Measures].[Fact Order Count], [Measures].[RANKRevenue] } ON COLUMNS, 
  NON EMPTY TopCount( { ([RevRank] ) } , 100, [Measures].[Revenue]) ON ROWS 
FROM [DW] 

由此我尝试在特定日期(日)拼接,然后将该等级与kpi中的前一天进行比较。所以,从我开始我正在努力打破这个查询。我创建了一个预先计算的集合和预先计算的成员来帮助我更轻松地完成这项工作。现在我只想弄清楚如何创建这个集合和成员一天,然后我至少可以在一天和下一天之间进行比较。

01/26/2012更新:好的,我在这方面还有一段距离,但是我仍然遇到了将排名引入我的查询的问题,下面的查询排名为空。希望有人可以通过此查询查看问题。

WITH MEMBER  [Measures].[PrevDayRevenue] AS
( [Measures].[Revenue], ParallelPeriod ([Date Link].[PK Date].[PK Date],1))
SET [RevRankPrevOrder] AS
ORDER (
   [Customer].[Customer Id].Members ,
   [Measures].[PrevDayRevenue],
   BDESC)
MEMBER [Measures].[RANKRevenuePrevOrder] AS RANK([Customer].CurrentMember, [RevRankPrevOrder])
SET [RevRankCurrOrder] AS
ORDER (
   [Customer].[Customer Id].Members ,
   [Measures].[Revenue],
   BDESC)
MEMBER [Measures].[RANKRevenueCurrOrder] AS RANK([Customer].CurrentMember, [RevRankCurrOrder])

SELECT NON EMPTY { [Measures].[Revenue],  [Measures].[PrevDayRevenue], [Measures].[RANKRevenuePrevOrder], [Measures].[RANKRevenueCurrOrder] } ON COLUMNS,
NON EMPTY { ( [RevRankCurrOrder] ) } ON ROWS 
FROM [DW] 
WHERE {[Date Link].[PK Date].&[2012-01-08T00:00:00]}

2 个答案:

答案 0 :(得分:1)

您可以使用ParallelPeriod功能计算前一天的排名。这也需要动态完成。

然后你可以比较你的KPI值中的两个......

CASE
    WHEN [Customer Rank Yesterday] - [Customer Rank Today] > 0 THEN 1
    WHEN [Customer Rank Yesterday] - [Customer Rank Today] = 0 THEN 0
    ELSE -1
END

答案 1 :(得分:0)

这是我完成的查询,希望这有助于其他人。 :

WITH MEMBER  [Measures].[PrevDayRevenue] AS
( [Measures].[Revenue], ParallelPeriod ([Date Link].[PK Date].[PK Date],1))

SET [RevRankPrevOrder] AS
ORDER (
   [Customer].[Customer Id].CHILDREN ,
   [Measures].[PrevDayRevenue],
   BDESC)

MEMBER [Measures].[RANKRevenuePrevOrder] AS 
    RANK(
    [Customer].[Customer Id].CurrentMember,
    [RevRankPrevOrder])

SET [RevRankCurrOrder] AS
ORDER (
   [Customer].[Customer Id].CHILDREN,
   [Measures].[Revenue],
   BDESC)

MEMBER [Measures].[RANKRevenueCurrOrder] AS RANK([Customer].[Customer Id].CurrentMember, [RevRankCurrOrder])

SELECT NON EMPTY { [Measures].[Revenue],  [Measures].[PrevDayRevenue], [Measures].[RANKRevenuePrevOrder], [Measures].[RANKRevenueCurrOrder]  } ON COLUMNS,
NON EMPTY { ( [RevRankCurrOrder] ) } ON ROWS 
FROM [DW] 
WHERE {[Date Link].[PK Date].&[2012-01-10T00:00:00]}