I have no training in writing queries myself. My company uses an OLAP Analysis Services database.
I've used Power Pivot to create the following query that selects static dates and it works fine. But what I want it to do is have a dynamic date range that rolls forward with time and I can't figure it out.
I want it to do the following:
- [Date].[Date] to only look at from yesterday to the last 365 days/1 year
- and [Item].[Last Receipt Date] to only pull in items last received 6 months ago or older
And as time moves on, it will adjust the date range when I refresh, always sticking to those windows.
The static dates in the query below were just for testing and aren't needed at all.
SELECT NON EMPTY { [Measures].[Sales Units] } ON COLUMNS, NON EMPTY { ([Reporting Currency].[Reporting Currency].[Reporting Currency].ALLMEMBERS * [Date].[Year].[Year].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( { [Item].[Last Receipt Date].&[2019-01-05], [Item].[Last Receipt Date].&[2019-01-06], [Item].[Last Receipt Date].&[2019-01-07], [Item].[Last Receipt Date].&[2019-01-09], [Item].[Last Receipt Date].&[2019-01-08] } )
ON COLUMNS FROM ( SELECT ( { [Date].[Date].&[2019-01-04T00:00:00], [Date].[Date].&[2019-01-05T00:00:00], [Date].[Date].&[2019-01-06T00:00:00] } ) ON COLUMNS FROM [IMR])) WHERE ( [Date].[Date].CurrentMember, [Item].[Last Receipt Date].CurrentMember
) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
Any help would be appreciated.