New to MDX and inherited an application using the following to retrieve the last 7 work days.
Note, the actual dates are generated dynamically.
WHERE ( [DimCalendar].[WorkDayHierarchy].[WorkDate].&[2016-03-25T00:00:00]
: [DimCalendar].[WorkDayHierarchy].[WorkDate].&[2016-03-26T00:00:00].lag(6)
)
I expected it to use the previous 7 work days:
2016-03-17
to2016-03-25
But instead, it uses future dates
2016-03-25
to latest date in DimCalendar
From what I've read, it's because 2016-03-26
doesn't exist in the hierarchy, so the end range becomes NULL, which explains the future dates...
[WorkDate].&[2016-03-25T00:00:00] : NULL
The problem is the date values are generated dynamically, and I don't know in advance which values exist in the hierarchy. I'm not sure how to construct the MDX date range to get the desired results.
I've tried using <=
and FILTER
but keep getting conversion errors. With plain SQL this would be easy. I could just write:
WHERE [WorkDate] >= '2016-03-17'
AND [WorkDate] <= '2016-03-25'
Any ideas what the equivalent filter would be in MDX?