3

I have successfully added basic sum/count/etc.. simple measures, but have no idea how to add more complex one.

Let's assume that data structure represent tracks with goods and have next structure:

  • date
  • id_track
  • id_articte
  • amount
  • cost

And want to calculate next measures:

  1. average item price, calculated as sum(cost) / sum(amount)
  2. average track cost. It's average between sum(cost) for whole tracks. Sql expression looks like sum(cost) / count(distinct id_track)

What is the right way to add this measures to my cube, in case i will need them in Excel over XMLA?

2 Answers2

3

Complex calculation are solved using what we call in MDX 'calculated measures'.

Calculated Measures support the whole power of MDX language. You can see more information about Calculated Measures here. They are very powerful and over 100 functions are supported (function list).

If you want to define a calculated measure once per schema I'd advise defining them in Advanced/Scripts in the Builder UI tab. You can first check validity in the MDX IDE and once validated move them to the Script.

ic3
  • 7,917
  • 14
  • 67
  • 115
  • Thanks for helping. I have successfully added one of them and stuck with second. I can't find how to write big and nice comments, so i have updated my question with more details – Oleksandr Voytsekhovskyy Oct 12 '15 at 20:49
1

average item price, calculated as sum(cost) / sum(amount)

This would look something like the following:

WITH MEMBER [Measures].[AvgPrice] AS
  AVG(
    EXISTING([Item].[Item].MEMBERS)
   ,[Measures].[COST]
  )
...

Or

WITH MEMBER [Measures].[AvgPrice] AS
  [Measures].[COST] 
  / 
  [Measures].[AMOUNT] 
...

average track cost. It's average between sum(cost) for whole tracks. Sql expression looks like sum(cost) / count(distinct id_track)

WITH MEMBER [Measures].[AvgTrackCost] AS
  AVG(
    EXISTING([TrackItem].[TrackItem].MEMBERS)
   ,[Measures].[COST]
  )
...

I've had to guess that the following exist within your cube:

[Measures].[COST]
[Measures].[AMOUNT] 
[Item].[Item].MEMBERS
[TrackItem].[TrackItem].MEMBERS
whytheq
  • 34,466
  • 65
  • 172
  • 267
  • Thanks for helping. I have successfully added one of them and stuck with second. I can't find how to write big and nice comments, so i have updated my question with more details – Oleksandr Voytsekhovskyy Oct 12 '15 at 20:48