问题
Hi I need to calculate No. of days between Counts so the dataset is
count
I have created a member of the last date, this returns the last date across the whole dataset as a start but not sure how to proceed. Is it possible to do this in MDX? if so how?
Thank you
MEMBER [Measures].[Last date] AS
MAX([Date].[Full Date].[Full Date].MEMBERS,
iif( [Measures].[Count] = 0,
null,
[Date].[Full Date].CurrentMember.MemberValue
)
)
回答1:
The following example will help. But please note that it will count from the begining of the month. So if there was an order was on 5 may and the last order was on 28 April then the diffrence would be 4 not 7.
with member measures.MonthDate as
[Date].[Day of Month].CurrentMember.Properties ("Member_Value",TYPED)
member measures.LastOrderDate as
(max(
FILTER(
[Date].[Day of Month].firstSibling:[Date].[Day of Month].currentmember.lag(1)
,[Measures].[Internet Order Count] > 0)
,measures.MonthDate)
)
member measures.DaysToLastOrder as
(max(
FILTER(
[Date].[Day of Month].firstSibling:[Date].[Day of Month].currentmember
,[Measures].[Internet Order Count] > 0)
,measures.MonthDate)
-measures.LastOrderDate
)
select
{
[Measures].[Internet Order Count],measures.DaysToLastOrder
}
on columns,
nonempty (([Date].[Month of Year].[Month of Year],[Date].[Day of Month].[Day of Month]),[Measures].[Internet Order Count])
on rows
from
[Adventure Works]
where ([Date].[Calendar Year].&[2012],[Customer].[City].&[London]&[ENG],[Product].[Subcategory].&[1]--,[Date].[Month of Year].&[11]
)
来源:https://stackoverflow.com/questions/53011717/mdx-difference-between-dates-non-null-and-of-the-same-dimension