MDX - 30 天内没有销售

发布于 2024-11-26 21:27:19 字数 720 浏览 0 评论 0原文

我想要获得 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 技术交流群。

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

发布评论

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

评论(2

献世佛 2024-12-03 21:27:19

函数 LastPeriods 就是您要寻找的:

 WITH 
  MEMBER [Measures].[Zero Sales Days] 
  AS COUNT(
        FILTER([Calendar].[Date].[Day], 
          SUM( LastPeriods(30, [Calendar].[Date].currentmember),[Measures].[POS Qty]) 
          = 0 )
        ) 
 SELECT 
  ([Store].[Store].[Store],[product].[product].[product]) on 1,
  ([MEASURES].[Zero Sales Days]) ON 0
 FROM [testcube]

The function LastPeriods is what you're looking for:

 WITH 
  MEMBER [Measures].[Zero Sales Days] 
  AS COUNT(
        FILTER([Calendar].[Date].[Day], 
          SUM( LastPeriods(30, [Calendar].[Date].currentmember),[Measures].[POS Qty]) 
          = 0 )
        ) 
 SELECT 
  ([Store].[Store].[Store],[product].[product].[product]) on 1,
  ([MEASURES].[Zero Sales Days]) ON 0
 FROM [testcube]
夏の忆 2024-12-03 21:27:19

以下查询适用于 Adventure Works,并向您显示自 WHERE 子句中的日期起超过 30 天没有销售的产品:

WITH
MEMBER [Measures].[Number of Periods With No Sales] AS
    Iif(([Date].[Date].CurrentMember, [Measures].[Internet Sales Amount])=0,
        ([Date].[Date].PrevMember, [Measures].[Number of Periods With No Sales])+1,
        NULL
    )
MEMBER [Measures].[Number of > 30 Periods With No Sales] AS
    Sum(
        Iif([Measures].[Number of Periods With No Sales] > 30,
            [Measures].[Number of Periods With No Sales],
            NULL
        )
    )
SELECT
{
    [Measures].[Number of > 30 Periods With No Sales]
} ON 0,
NON EMPTY {
    [Product].[Product Categories].[Product]
} ON 1
FROM [Adventure Works]
WHERE [Date].[Calendar].[Date].&[860]

您将需要重新处理它(更改维度/度量名称)以使其适用你的数据库。如果您需要一项查询,该查询可以为您提供所有产品(无论日期如何),并且至少有一个时期超过 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:

WITH
MEMBER [Measures].[Number of Periods With No Sales] AS
    Iif(([Date].[Date].CurrentMember, [Measures].[Internet Sales Amount])=0,
        ([Date].[Date].PrevMember, [Measures].[Number of Periods With No Sales])+1,
        NULL
    )
MEMBER [Measures].[Number of > 30 Periods With No Sales] AS
    Sum(
        Iif([Measures].[Number of Periods With No Sales] > 30,
            [Measures].[Number of Periods With No Sales],
            NULL
        )
    )
SELECT
{
    [Measures].[Number of > 30 Periods With No Sales]
} ON 0,
NON EMPTY {
    [Product].[Product Categories].[Product]
} ON 1
FROM [Adventure Works]
WHERE [Date].[Calendar].[Date].&[860]

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.

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