2
votes

I want to compare actual sales values with sales values of last year. The difficulty in this comparison is the compliance of the week days and thereby of the leap-year.

Example on day level:

2016-02-04 (thursday): actual sales: 580,- last year sales: 1.008,-

comparison with

2015-02-05 (thursday): actual sales: 1.008,-

So i want to compare the same week days in the month and not only the same dates.

Example on month level:

2016: (leap-year) 01.02.2016 - 29.02.2019 (february 2016) actual Sales: 19.300,- : last year Sales value: 19.000,-

comparison with

2015: (no leap year) 02.02.2015 - 02.03.2015 (february 2015 on week day logic) actual sales value: 19.000,-

I want not only compare February 2016 with february 2015 rather exactly the week day sales values summed.

I tried to write this calculation with an date calculation dimension and it works but only on the day level. Name of the calculation dimension: Date Calculations Week Day name of the member: ComparisonWD

SCOPE ( 
    [Date].[Year - Quarter - Month - Date].MEMBERS,
    [Date].[Date].MEMBERS );                    


( [Date Calculations Week Day].[ComparisonWD].[Previous Year], 
      [Date Calculations Week Day].[AggregationWD].Members ) 
          = ( [Date Calculations Week Day].[ComparisonWD].DefaultMember,
              ParallelPeriod( [Date].[Year - Quarter - Month - Date].[Date],
                              364,
                              [Date].[Year - Quarter - Month - Date].CurrentMember ) );            
END SCOPE;

Result 2015:

enter image description here

Result 2016:

enter image description here

It works on day level, but as you seen not on the month and not onthe year level.

enter image description here

How can I achieve this?

3

3 Answers

1
votes

I got the solution:

Cube Calculation Code for this problem:

// ------------------------------------------------------------------------
//
//    Comparison Week Day - Date.Calendar
//
// ------------------------------------------------------------------------
SCOPE ( 
    [Date].[Year - Quarter - Month - Date].MEMBERS,
    [Date].[Date].MEMBERS );                    

    ///////////////////////////////////////////////////////////////////////////////////////
    ( [Date Calculations Week Day].[ComparisonWD].[Previous Year], 
      [Date Calculations Week Day].[AggregationWD].Members ) 
          = SUM({ParallelPeriod([Date].[Year - Quarter - Month - Date].[Date], 364, Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Year - Quarter - Month - Date].[Date]).item(0)) :
                     Parallelperiod ([Date].[Year - Quarter - Month - Date].[Date], 364,  Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Year - Quarter - Month - Date].[Date]).item((Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Year - Quarter - Month - Date].[Date])).Count - 1))}, [Date Calculations Week Day].[ComparisonWD].DefaultMember );            
END SCOPE;    


SCOPE ([Date Calculations Week Day].[ComparisonWD].[Diff. Over Previous Year]);                   
    THIS = IIF( IsEmpty( [Date Calculations Week Day].[ComparisonWD].DefaultMember ) 
                         OR IsEmpty( [Date Calculations Week Day].[ComparisonWD].[Previous Year] ),
                NULL,
                [Date Calculations Week Day].[ComparisonWD].DefaultMember 
                - [Date Calculations Week Day].[ComparisonWD].[Previous Year] );                   
    NON_EMPTY_BEHAVIOR(THIS) = [Date Calculations Week Day].[ComparisonWD].DefaultMember;                   
    FORE_COLOR(THIS) = IIF( [Date Calculations Week Day].[ComparisonWD].[Diff. Over Previous Year] < 0, 255, 0);                     // 255 = RED
END SCOPE;                   

SCOPE ([Date Calculations Week Day].[ComparisonWD].[Diff. % Over Previous Year]);                   
    THIS = IIF( IsEmpty( [Date Calculations Week Day].[ComparisonWD].[Diff. Over Previous Year] ) 
                         OR IsEmpty( [Date Calculations Week Day].[ComparisonWD].[Previous Year] ),
                NULL,
                [Date Calculations Week Day].[ComparisonWD].[Diff. Over Previous Year]
                / [Date Calculations Week Day].[ComparisonWD].[Previous Year] );                   
    NON_EMPTY_BEHAVIOR(THIS) = [Date Calculations Week Day].[ComparisonWD].DefaultMember;                   
    FORMAT_STRING(THIS) = 'Percent';                   
    FORE_COLOR(THIS) = IIF( [Date Calculations Week Day].[ComparisonWD].[Diff. % Over Previous Year] < 0, 255, 0);                     // 255 = RED
END SCOPE;                   

///////////////
// Tuple (All years, All Months) is the default number (keeps compatibility with OWC11)
( [Date].[Year].[All], [Date].[MonthYear].[All],
  Except( [Date Calculations Week Day].[ComparisonWD].[ComparisonWD].MEMBERS, [Date Calculations Week Day].[ComparisonWD].DefaultMember ) ) = [Date Calculations Week Day].[ComparisonWD].DefaultMember;   

Now with summed values on every level:

enter image description here

With this Date Calculations Week Day Dimension you can show for every Measure the Prev Year Values on Week day logic.

0
votes

Not exactly answering the question but in the following context PARALLELPERIOD seems quite generic:

1. At the Month level:

WITH 
  MEMBER [Measures].[PY Internet Sales Amount] AS 
    (
      ParallelPeriod
      (
        [Date].[Calendar].[Calendar Year]
       ,1
       ,[Date].[Calendar].CurrentMember
      )
     ,[Measures].[Internet Sales Amount]
    ) 
SELECT 
  {
    [Measures].[Internet Sales Amount]
   ,[Measures].[PY Internet Sales Amount]
  } ON 0
 ,{
      //[Date].[Calendar].[Date].&[20130101]:[Date].[Calendar].[Date].&[20130601]
      [Date].[Calendar].[Month].[January 2012]:[Date].[Calendar].[Month].[December 2013]
  } ON 1
FROM [Adventure Works];

Gives this:

enter image description here

2. Changing to the Date level but leaving the PARALLELPERIOD calculation the same:

WITH 
  MEMBER [Measures].[PY Internet Sales Amount] AS 
    (
      ParallelPeriod
      (
        [Date].[Calendar].[Calendar Year]
       ,1
       ,[Date].[Calendar].CurrentMember
      )
     ,[Measures].[Internet Sales Amount]
    ) 
SELECT 
  {
    [Measures].[Internet Sales Amount]
   ,[Measures].[PY Internet Sales Amount]
  } ON 0
 ,{
      [Date].[Calendar].[Date].&[20130101]:[Date].[Calendar].[Date].&[20130601]
      //[Date].[Calendar].[Month].[January 2012]:[Date].[Calendar].[Month].[December 2013]
  } ON 1
FROM [Adventure Works];

Gives these results (no NULLS):

enter image description here

0
votes

Just tried to imitate the problem as a mdx query in ssms and it works. How can i apply on my cube calculation:

with 
 set [DateRange] as ( { ParallelPeriod([Date].[Year - Quarter - Month - Date].[Date], 
                        364, 
                        Descendants( [Date].[Year - Quarter - Month - Date].[Year].&[2013] , [Date].[Year - Quarter - Month - Date].[Date]).item(0)
                         ) :
                        Parallelperiod ([Date].[Year - Quarter - Month - Date].[Date], 
                        364,  
                        Descendants( [Date].[Year - Quarter - Month - Date].[Year].&[2013] , [Date].[Year - Quarter - Month - Date].[Date]).item((Descendants( 
                                                                                                                                                    [Date].[Year - Quarter - Month - Date].[Year].&[2013] , [Date].[Year - Quarter - Month - Date].[Date])).Count - 1))})


Select  { 
          [Measures].[Turnover] 
       } on Columns, 
non empty
       (
         [DateRange]
       ) on Rows
from [Sales Cube] 

Following result:

Turnover Net
03.01.2012  642
04.01.2012  665
05.01.2012  633
06.01.2012  730
07.01.2012  761
08.01.2012  531
09.01.2012  422
10.01.2012  488
11.01.2012  518
.
.
.
23.12.2012  618
24.12.2012  174
25.12.2012  137
26.12.2012  536
27.12.2012  981
28.12.2012  1.052
29.12.2012  1.006
30.12.2012  847
31.12.2012  695
01.01.2013  572

So you see, the date range is correct 2012-01-03 - 2013-01-01

In the query i take the date and descendant it to the lowest level (day) and then generate a date range. First date of range - 364 days and the last date of range -364 days to get the correct date range. Unfortunately i doesn't works in the cube calculation:

// ------------------------------------------------------------------------
//
//    Comparison Week Day - Date.Calendar
//
// ------------------------------------------------------------------------
SCOPE ( 
    [Date].[Year - Quarter - Month - Date].MEMBERS,
    [Date].[Date].MEMBERS );                    

    ///////////////////////////////////////////////////////////////////////////////////////
    ( [Date Calculations Week Day].[ComparisonWD].[Previous Year], 
      [Date Calculations Week Day].[AggregationWD].Members ) 
          = SUM( [Date Calculations Week Day].[ComparisonWD].DefaultMember,
              {ParallelPeriod([Date].[Year - Quarter - Month - Date].[Date], 364, Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Date]).item(0)) :
                     Parallelperiod ([Date].[Year - Quarter - Month - Date].[Date], 364,  Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Date]).item((Descendants( [Date].[Year - Quarter - Month - Date].CurrentMember , [Date].[Date])).Count - 1))} );            
END SCOPE;