Monday, March 12, 2012

MDX to fetch last 300 non empty dates?

Can someone enlighten me on how to return the last 300 dates worth of data from an MDX query?

For instance, this returns me all the dates in 2007...

SELECT ([Measures].[Total]) ON 0,
NON EMPTY [Calendar].[Date].CHILDREN ON 1
FROM [DB]
WHERE ([Calendar].[Year].[2007])

But let's say I want to return the last 300 non-empty dates and their "Total" value? (The Calendar dimension has the standard Year, Month, Date hierarchy...)

Thanks in advance.

How about something like this:

SELECT ([Measures].[Total]) ON 0,

Tail(

Filter(

([Calendar].[Date].CHILDREN) As S

Not IsEmpty(S.Current))

,300)

ON 1

FROM [DB]

This should return the last 300 non empty dates.

Van Dieu

|||Thanks Van -- very helpful. For some reason the "Not IsEmpty(...)" didn't work, but no worries, this workaround did...

TAIL(FILTER([Calendar].[Date].CHILDREN, ABS([Measures].[P&L Total]) > 1), 300)

No comments:

Post a Comment