如何编写 MDX 语句或查询来选择上个月付款但本月尚未付款的客户?

发布于 2024-12-21 06:27:48 字数 122 浏览 3 评论 0原文

如何编写 MDX 语句或查询来选择上个月付款但本月尚未付款的客户?我在 Microsoft SQL Server Analysis Services R 2 上设计并部署了一个数据立方体。我有一个客户维度和一个事实表。 请帮忙。

How can I write an MDX statement or query that selects the clients who paid last month but have not paid this(Current Month) month?. I have a data cube designed and deployed on Microsoft SQL Server Analysis Services R 2. I have a customer dimensions and a fact table.
Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

场罚期间 2024-12-28 06:27:48

我假设您有一个 [时间] 维度,以及一个包含客户已付款的值的度量。我认为 Filter() 函数将帮助您将所有客户端的集合减少到仅您感兴趣的客户端。

SELECT {Filter({[Client].[SomeLevel] .members}, ([时间].[上个月], [测量].[任意]) > 0 AND ([时间].[本月], [测量].[任意]) = 0} ON ROWS, {[Measures].[whatever]} ON COLUMNS FROM [CubeName]

您可能很难决定使用什么来代替我写的 [Time].[ThisMonth] - 请参阅 StackOverflow 上的其他答案以选择“当前的日期。

I assume you have a [Time] dimension, and a measure that contains a value if the client has paid. I think the Filter() function will help you reduce a set of all clients down to just the clients that you're interested in.

SELECT {Filter({[Client].[SomeLevel].members}, ([Time].[LastMonth], [Measures].[whatever]) > 0 AND ([Time].[ThisMonth], [Measures].[whatever]) = 0} ON ROWS, {[Measures].[whatever]} ON COLUMNS FROM [CubeName]

You trouble might be deciding what to use in place of where I wrote [Time].[ThisMonth] - see other answers here on StackOverflow for selecting 'current' dates.

蓝眼睛不忧郁 2024-12-28 06:27:48

首先,您必须确定当前月份和上个月。一种方法是使用 VBA!Date 函数计算它。

因此,如果您的日期以 12/31/2014 格式存储,并假设您有一个度量 Payment 和一个带有 Year-Quarter-Month- 的日期维度, Date 层次结构,下面的代码可以帮助您。

WITH MEMBER [Measures].ValueThisMonth AS
(
 [Date].[Year-Quarter-Month-Date].CURRENTMEMBER.PARENT, 
 [Measures].[Payment]
)

MEMBER [Measures].ValueLastMonth AS
(
 [Date].[Year-Quarter-Month-Date].CURRENTMEMBER.PARENT.LAG(1), 
 [Measures].[Payment]
)

SELECT [Client].[Client Name].MEMBERS
HAVING ISEMPTY([Measures].ValueThisMonth)
AND NOT(ISEMPTY([Measures].ValueLastMonth))
ON 0
FROM [Your cube]
WHERE 
StrToMember("[Date].[Year-Quarter-Month-Date].[Date].&[" + FORMAT(VBA![Date](), "MM/dd/yyyy") + "]" + "]")

相反,如果您想从前端传递此“当前”值,请在 WHERE 子句中使用参数。

First of all, you have to identify the current month and the last month. One way to do it is compute it using the VBA!Date function.

So if your dates are stored in the format 12/31/2014 and assuming you have a measure Payment and a Date dimension with a Year-Quarter-Month-Date hierarchy, the below code can help you.

WITH MEMBER [Measures].ValueThisMonth AS
(
 [Date].[Year-Quarter-Month-Date].CURRENTMEMBER.PARENT, 
 [Measures].[Payment]
)

MEMBER [Measures].ValueLastMonth AS
(
 [Date].[Year-Quarter-Month-Date].CURRENTMEMBER.PARENT.LAG(1), 
 [Measures].[Payment]
)

SELECT [Client].[Client Name].MEMBERS
HAVING ISEMPTY([Measures].ValueThisMonth)
AND NOT(ISEMPTY([Measures].ValueLastMonth))
ON 0
FROM [Your cube]
WHERE 
StrToMember("[Date].[Year-Quarter-Month-Date].[Date].&[" + FORMAT(VBA![Date](), "MM/dd/yyyy") + "]" + "]")

If instead you would like to pass this "current" value from the front end, use a parameter in the WHERE clause.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文