简体   繁体   中英

SSAS - MDX calculated member

I've a fact table that details individual line amounts for orders placed by my organisation. In this fact, at line level, I've included the total order amount to be used, as it's possible we might need that level of detail at some point.

Here's an example of what I've got:-

+------------+------------+---------------+------------+---------------------+
| BookingKey | Booking_ID | Category_FKey | Line_Value | Total_Booking_Value |
+------------+------------+---------------+------------+---------------------+
|          1 |         12 |             8 |        150 |                 700 |
|          2 |         12 |             4 |        150 |                 700 |
|          3 |         12 |             5 |        300 |                 700 |
|          4 |         12 |             4 |        100 |                 700 |
+------------+------------+---------------+------------+---------------------+

As you can see, the Total_Booking_Value here is the sum of the Line_Value for the booking in the example (Booking_ID = 12).

The Category_FKey looks up to a Categories dimension.

Using this structure I've created a simple cube and this works fine, mainly.

The issue I have is that I'd like to be able to view the Total Line_Value amount, and somehow include the Total_Booking_Value alongside it.

So, for example I might add the Categories dimension as a filter and want to filter by say Category_FKey = 4.

If this was the case I'd want the aggregates to tell me that the total Line_Value was 250 (for BookingKeys 2 and 4), and the Total_Booking_Value should be 700. Using normal aggregation (ie SUM) I'm getting the Total_Booking_Value as 1400 (obviously - because it's adding 700 * 2 for the two rows the cube would return).

So, the way I see it I'd like to create an MDX calculation that somehow takes the Total_Booking_Value and gives just the value for the Booking in question.

Should this be done using some kind of average, or division by the Distinct number of items? I can't figure this out. I tried something like this:-

create member currentcube.measures.[Calculated Booking Value]
as
[Measures].[Total_Booking_Value] / count(Measures.Booking_ID);

But this isn't working.

Hopefully this makes sense and you can point me in the right direction.

I find it strange that booking_ID is a measure - intuitively it strikes me as something that would be an attribute and therefore a hierarchy - in which case you'd be able to do the count like this:

[Measures].[Total_Booking_Value] 
/ 
COUNT(EXISTING [Booking].[Booking_ID].[Booking_ID].members)

A straightforward solution would be to have two fact tables: one with granularity booking key and one with granularity booking id. The first would contain all columns except total booking value, and the second would contain columns booking id and total booking value.

Then each of both measures would easily be summable.

The reference type between the second fact table and the category dimension could be configures as many-to-many via the first fact table. Thus, you would see the full values of the involved bookings for each selected category, automatically eliminating double counting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM