| MDX-How do I calculate sales for 12 Month to date? |
| Written by Vidas Matelis | |||||||||||||||||||||||||||||||
| Friday, 08 June 2007 02:44 | |||||||||||||||||||||||||||||||
|
Q: How do I calculate sales for 12 Month to date in MDX? A: We have to assume that your date dimension last member represents last month. Then to get last 12 month we can use Lag function. Example: SELECT [Measures].[Order Count] ON 0 Result:
Now to get sum of sales query could be :
Result
|
Most read
- How to install Adventure Works SQL DW and Analysis Services 2005/2008 sample database and project
- MDX-How can I get Last (Previous) Year to Date (YTD) values?
- What TCP port SQL Server Analysis Services 2005 uses
- MDX-How do you calculate monthly average of one year, optionally including empty months?
- MDX-How do I calculate sales for 12 Month to date?








date count to-date
1/1/08 2 2
1/12/09 1 3
PeriodsToDate(
[Date].[Calendar].[Year],
[Date].[Calendar].[Year].[@Year]
),
[Measures].[Sales Amount])
I defined the parameter in dataset whose value i set to the report parameter, It is not working Above is what i modified when i defined parameter. Can any body help me plz how to parameterized year in above code?
Thanks
Aggregate(
PeriodsToDate(
[Date].[Calendar].[Year],
[Date].[Calendar].[Year].[Year 2007]
),
[Measures].[YourMeasure])
I used this code to calculate the YTD Measure using Add Calculated tool, It worked fine but when i used it in report using expression just like other Field values, It gives me Output in "xml" kinda form instead of Values. In query pane it works fine. Any body have Idea how i will use this calculated Measure in report?
Thanks
Regards
Is there any way that we can use just expressions for this instead of MDX query?
WITH MEMBER [Measures].[Last 12 Mth Order Count] AS
SUM(
ClosingPeriod([Date].[Month].[Month], [Date].[Month].[All]).Lag(12)
: ClosingPeriod([Date].[Month].[Month], [Date].[Month].[All])
, [Measures].[YourMeasure]
)
SELECT [Measures].[Last 12 Mth Order Count] ON 0
FROM [Your Cube]