0
votes

I'm using a calculated member for "previous period" as:

Case
// Test for current coordinate being on (All) member.
When [<<Target Dimension>>].[<<Target Hierarchy>>].CurrentMember.Level Is
     [<<Target Dimension>>].[<<Target Hierarchy>>].[(All)]

Then "NA"

Else ( 
       ParallelPeriod
       (
          [<<Target Dimension>>].[<<Target Hierarchy>>].[<<Target Level>>],
          <<Number of Periods>>,
          [<<Target Dimension>>].[<<Target Hierarchy>>].CurrentMember
       ),
       [Measures].[<<Target Measure>>] 
     )
End

// This expression evaluates the difference between the value of the numeric
// expression in the previous period and that of the current period.

(snippet code taken directly from Microsoft suggestion)

It works as expected but when presenting the Totals I get the whole Year total, even if only some months are selected on rows.

So, if I select say year 2015, months Jan to Jun, I get the six correct values for 2014 months but a 2014 grand total instead of the sum of the six presented values.

Any way to get the "correct" sum value? By correct I mean the sum of the selected rows.

Edited to add the actual code:

Case
When [Dim Time].[Calendar].CurrentMember.Level Is [Dim Time].[Calendar].[(All)]
Then "NA"
Else (ParallelPeriod([Dim Time].[Calendar].[Year],
      1,
      [Dim Time].[Calendar].CurrentMember),[Measures].[Sales])
End

My Dim Time.Calendar has Year-Month-Day as levels. Easy enough :)

When selecting some months the Year total is the Grand total of the year, not the total of the selected months. When selecting some days, the Month total is the Grand total of the month, not the total of the selected days.

Edited to add example:

Year    Month   Day Sales previous year Sales
2015    04      03      74,154.56 €     135,156.41 €
    Total 04         2,617,045.75 €     135,156.41 €
Total 2015          37,696,665.69 €     135,156.41 €
2
Hi DeepButi - was anyone able to help you with any of your previous mdx questions? Such as this one: stackoverflow.com/questions/31000705/…whytheq
The one you are pointing at was solved but only for Mondrian (as you said). Some other questions I asked directly on other forums because they were specific to the tools used (Pentaho suite). But this one is generic, I'm using MicroSoft Olap cubes and Excel dinamic tables. I thought this forums would be the logical place to ask. Maybe I'm wrong ...DeepButi
Where is the calculation going - in the cube script, or in Excel? Which version of Excel are you using? (2013 has custom measure mdx functionality)whytheq
Excel 2013. I guess the total is calculated at client (excel) side but for base measures it's ok, even for calculated members where no time is involved (i.e. [Measures].[Sales]-[Measures].[Cost]), only cm with parallelperiod or similar produce the incorrect result. I wanted to try solve_order but I cannot use it on the cm definition as it is not accepted by the VisualStudio tool defining the cube.DeepButi
ok - so you are adding this cm into the cube script - did you try adding a measure into Excel?whytheq

2 Answers

0
votes

(unsure if I should post an answer because it's not yet solved, but seems I found the right direction)

Using the suggestions here I defined a dynamic set (at cube definition time using MS SAS):

CREATE DYNAMIC SET CURRENTCUBE.[DynSet] AS [Dim Time].[Calendar]

and a Calculated member (on Excel, easier to test diferent syntax):

count([DynSet])

Now I get 1 as value on all rows, individual ones, subtotals, totals ... instead of the expected days of the selected month and the total sum.

Maybe someone with better MDX knowledge can develop it further.

I added also CM using the examples of the post count(descendants and count(existing( ... of the original [Dim Temps].[Calendar] and this is what I get:

    Year    Month   Day Previous sales  Sales          CountExisting    CountDescendants    CountDays
    2015    04      03      74,154.56 € 135,156.41 €      1   1 1
                    04     132,992.88 € 152,179.24 €      1   1 1
                    05     130,651.80 € 128,971.65 €      1   1 1
    Total 04             2,617,045.75 € 416,307.30 €     31  31 1
Total 2015              37,696,665.69 € 416,307.30 €    365 365 1

I cannot understand how to use the new dynamic set as I'm not able to access its components, I expected [DynSet].[Year] [Month] and [Day] to exist so I could use them on my previous period expressions but they don't, so unsure on how to use it for my purpose.

Thks

Edited:

Tried to define

CREATE DYNAMIC SET CURRENTCUBE.[DynSet] AS [Dim Time].[Calendar].[Day]

and now my last column i.e. count([DynSet]) has a value of 3 for all lines.

Still no idea how to use [DynSet] levels ...

0
votes

It took me almost two weeks, lots of searching hours and a dozen diferent forums, but finally I got a decent answer that solved the problem.

Take a look here

In brief, add a named calculation (not a calculated member) and scope the formula

SCOPE([Measures].[Previous_Sales]);
    SCOPE([Dim Time].[Calendar].[Day].MEMBERS);
            THIS = ([Measures].[Sales], ParallelPeriod([Dim Time].[Calendar].[Year])) ;
    END SCOPE;
END SCOPE;

Simple enough once you know it!