【问题标题】:How to get Last Selling Price in MDX如何在 MDX 中获取最后售价
【发布时间】:2023-03-08 08:02:01
【问题描述】:

MDX 能否按照以下代码返回预期结果? 数据如下:

DATA:       
ItemID  DateKey Price
A   20151230    4.85
A   20150520    5.5
A   20150325    4.65
B   20140130    3
B   20141130    5
B   20150630    4.5

Wrong Result:
ItemID  DateKey Price
A   20151230    4.65
B   20150630    3

Expected Result:
ItemID  DateKey Price
A   20151230    4.85
B   20150630    4.5

WITH MEMBER [LastDate] AS tail (Filter([BI Dim Date].[Date Key].[Date Key],[Measures].[PRICE])).Item(0).name
MEMBER [LastDateWithSales] AS Filter([MyTest].[PRICE].[PRICE],[Measures].[LastDate]).Item(0).name

SELECT { [LastDate], [LastDateWithSales]} ON columns,
[MyTest].[ITEMID].[ITEMID] on rows
FROM [MyCube]

执行上面的 MDX 但得到错误的结果。请指教。

【问题讨论】:

    标签: sql ssas mdx


    【解决方案1】:
    WITH MEMBER [LastDate] AS 
      tail (
         NonEmpty(
            [BI Dim Date].[Date Key].[Date Key].Members
           ,[Measures].[PRICE]
         )
       ).Item(0).Item(0).name
    MEMBER [LastDateWithSales] AS 
      tail (
         NonEmpty(
           [BI Dim Date].[Date Key].[Date Key].Members 
         * [Measures].[PRICE]
         )
       ).Item(0)
    
    SELECT 
    { [Measures].[LastDate], [Measures].[LastDateWithSales]} ON columns,
    [MyTest].[ITEMID].[ITEMID] on rows
    FROM [MyCube]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多