Quantcast
Channel: SQL Server Analysis Services forum
Viewing all articles
Browse latest Browse all 14337

MDX Month to Date Comparitive

$
0
0

Hi folks,

I want to track cumulative Sales within a month, as a comparison for the same day of the same Month in previous Years.
So, 

I want the following:

Slicer (Filter) : Month of Year = [Date].[Months]
Rows : Day of Month = [Date].[Days]
Columns : Year = [Date].[Calendar].[Year]
Measure : SalesUnits-MonthToDate = [Measures].[Quantity]

Getting this with SalesUnits for each day is easy:

SELECT NON EMPTY
     {[Date].[Calendar].[Year].&[2014]:[Date].[Calendar].[Year].&[2016]} ON 0
   , {[Date].[Days].[Day Of Month]} ON 1
FROM [Sales]
WHERE [Date].[Months].&[8]

However, getting it for Cumulative Month to Date calculated values, is proving a little tricky.

WITH
MEMBER [Measures].[QtyMTD]
AS Aggregate (
      PeriodsToDate (
         [Date].[Calendar].[Month]
         ,[Date].[Calendar].CurrentMember
         )
      ,[Measures].[Quantity]
   )

SELECT NON EMPTY
     CROSSJOIN(
         {[Date].[Calendar].[Year].&[2014]:[Date].[Calendar].[Year].&[2016]}
       , {[Measures].[Quantity], [Measures].[QtyMTD]}
       )  ON 0
   , {[Date].[Days].[Day Of Month]} ON 1
FROM [Sales]
WHERE [Date].[Months].&[8]

My results are empty for QtyMTD, and I'm stumped.  In this query, I would expect to see another three columns for QtyMTD for 2014, 2015, 2016.  Any help would be greatly appreciated.




How would I do this?


So, I want the Green Data below, not the Blue Data 

Day 2014 2015 2016 Day 2014 2015 2016
1 336 20 0 1 336 20 0
2 0 0 842 2 336 20 842
3 0 1,199 300 3 336 1,219 1,142
4 402 2,593 1,693 4 738 3,812 2,835
5 3,396 981 1,905 5 4,134 4,793 4,740
6 2,329 2,488 0 6 6,463 7,281 4,740
7 1,825 3,602 0 7 8,288 10,883 4,740
8 917 0 2,486 8 9,205 10,883 7,226
9 393 0 0 9 9,598 10,883 7,226
10 -548 0 603 10 9,050 10,883 7,829
11 1,192 3,140 1,306 11 10,242 14,023 9,135
12 2,811 1,740 1,640 12 13,053 15,763 10,775
13 1,109 2,425 96 13 14,162 18,188 10,871
14 3,443 1,756 0 14 17,605 19,944 10,871
15 2,204 0 2,037 15 19,809 19,944 12,908
16 572 0 1,351 16 20,381 19,944 14,259
17 0 3,096 943 17 20,381 23,040 15,202
18 2,689 2,457 1,434 18 23,070 25,497 16,636
19 1,870 3,271 2,285 19 24,940 28,768 18,921
20 1,739 3,216 0 20 26,679 31,984 18,921
21 3,293 4,248 0 21 29,972 36,232 18,921
22 3,122 2,189 4,832 22 33,094 38,421 23,753
23 1,101 0 2,843 23 34,195 38,421 26,596
24 0 18 2,569 24 34,195 38,439 29,165
25 2,877 7,444 7,344 25 37,072 45,883 36,509
26 3,555 2,917 2,342 26 40,627 48,800 38,851
27 2,119 5,400 2,060 27 42,746 54,200 40,911
28 767 3,128 0 28 43,513 57,328 40,911
29 3,497 101 4,122 29 47,010 57,429 45,033
30 2,481 0 7,575 30 49,491 57,429 52,608
31 2,572 2,493 6,655 31 52,063 59,922 59,263

Heeeeelllllppp!




Blue Peter



Viewing all articles
Browse latest Browse all 14337

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>