简体   繁体   中英

How to get Last Selling Price in MDX

Can MDX return the Expected Result as per code below? Have the data as per below :

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]

Execute the above MDX but get wrong result. Please advise.

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM