MDX - 30 天内没有销售
我想要获得 30 天内销量为零的产品。例如,下面是我的预期结果: 商店、产品、天数 商店 1、产品 1、33 商店 1、产品 2、100 商店 2、产品 5、96 商店 34、产品 14、78 Store100, Product9, 47
所以我写了下面的查询:
WITH
MEMBER [Measures].[Zero Sales Days]
AS
COUNT(
FILTER(
NONEMPTY( [Calendar].[Date].[Day],[Measures].[POS Qty])
, ( [Measures].[POS Qty]=0)
)
)
SELECT
([Store].[Store].[Store],[product].[product].[product]) on 1,
([MEASURES].[Zero Sales Days]) ON 0
FROM [testcube]
问题是: 如何过滤案例:零销售天数<30
谢谢, Nia
我做了一些改变,然后运行了我的数据库。 如果我添加了 where 原因,我什么也得不到。如果不是,结果是“#Error”。
我不需要选择任何与时间相关的维度。我想要对报告做的是:选择商店和产品维度,并定义一个计算度量来获取计数。 Boyan,如果您能需要详细的查询,我将非常感激。
I'd like to get the product with zero sales over 30 days. E.g. Below is my expected result:
Store,Product,Days
Store1, product1, 33
Store1, product2, 100
Store2, product5, 96
Store34, product14, 78
Store100, product9, 47
So I wrote below query:
WITH
MEMBER [Measures].[Zero Sales Days]
AS
COUNT(
FILTER(
NONEMPTY( [Calendar].[Date].[Day],[Measures].[POS Qty])
, ( [Measures].[POS Qty]=0)
)
)
SELECT
([Store].[Store].[Store],[product].[product].[product]) on 1,
([MEASURES].[Zero Sales Days]) ON 0
FROM [testcube]
The problem is: How to filter the case: days of zero sales<30
Thanks,
Nia
I did some change and then ran against my DB.
I got nothing if I added the where cause. If not, the result is '#Error'.
I need not select any time related dimension. What I want to do for the report is: select store and product dimension, and define a calculated measure to get the count. Boyan, I will be really appreciated it if you can need the detailed the query for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
函数 LastPeriods 就是您要寻找的:
The function LastPeriods is what you're looking for:
以下查询适用于 Adventure Works,并向您显示自 WHERE 子句中的日期起超过 30 天没有销售的产品:
您将需要重新处理它(更改维度/度量名称)以使其适用你的数据库。如果您需要一项查询,该查询可以为您提供所有产品(无论日期如何),并且至少有一个时期超过 30 天没有销售(例如没有销售的最长时期,或任意这样的时期),请告诉我。这需要进行一些更改。此外,由于查询使用递归,它可能会很慢 - 如果太慢,我们可以看到如何提高其性能 - 这可能需要更改数据模型以支持这一点分析。
The following query works against Adventure Works and shows you the products with no sales for over 30 days from the date in the WHERE clause back:
You will need to re-work it (change the dimension/measure names) to get it to work against your db. Please let me know if you need a query which can give you all products regardless of the date, which have at least one period with more than 30 days with no sales (e.g. max period with no sales, or an arbitrary such period). This will require a few changes. Also, since the query is using recursion it may be slow - if it is too slow we can see how to improve its performance - something which may require changes to your data model to support this bit of analytics.