首页 > 解决方案 > 来自 AdventureWorks 的 SSAS 不同销售客户

问题描述

我目前正在尝试逐月从 Adventure Works 立方体中获得不同的回头客数量。

因此,如果客户在 2014 年 10 月和 2014 年 11 月进行了一对多的购买,那么他们将在 2014 年 11 月计算一次。

如果它们在 2014 年 10 月但不在 2014 年 11 月,则它们不会被计算在内。

如果它们不在 2014 年 10 月,但它们在 2014 年 11 月,则它们不会被计算在内。

我的查询目前如下所示:

WITH
MEMBER MEASURES.[Returning Customers] AS
DISTINCTCOUNT(
NONEMPTY(
NONEMPTY(
[Customer].[Customer].MEMBERS
, [Measures].[Sales Amount])
, {[Measures].[Sales Amount]}
* [Date].[Calendar].[Month].CURRENTMEMBER.PREVMEMBER
)
)
SELECT
{
MEASURES.[Returning Customers]
} ON COLUMNS,
[Date].[Calendar].[Month].MEMBERS ON ROWS
FROM [Adventure Works]

这显示了月份列表,但每一列都有一个#Error。我究竟做错了什么?

标签: ssas

解决方案


双击#Error 以获取错误消息会有所帮助。但让我猜你的问题是 CurrentMember 不是 Month 级别的函数,而是 Calendar 层次结构。尝试以下操作:

WITH
MEMBER MEASURES.[Returning Customers] AS
COUNT(
NONEMPTY(
NONEMPTY(
[Customer].[Customer].[Customer].MEMBERS
, [Measures].[Sales Amount])
, ([Measures].[Sales Amount],[Date].[Calendar].CURRENTMEMBER.PREVMEMBER)
)
)
SELECT
{
MEASURES.[Returning Customers]
} ON COLUMNS,
[Date].[Calendar].[Month].MEMBERS ON ROWS
FROM [Adventure Works]

推荐阅读