Question

I have a fact table with the following rows:

WorkerName, OrderId, NumberOfPackagesPerOrder

Note that neither WorkerName nor OrderId is unique in this fact table. Multiple users could work on a single OrderId Also note that NumberOfPackagesPerOrder only depends on the OrderId, i.e. for every OrderId, the number of NumberOfPackagesPerOrder will be the same.

I am trying to build a cube to report hierarchical report from this data by employee hierarchy:

ManagerLevel1           [Total orders completed] [Total Packages Shipped]
    Managerlevel2
      .....
        ManagerLevelN
                  Worker

Since multiple workers could work on the same order, I need to avoid double counting PackagesPerOrder for manager levels (non leaf nodes).

Manager hierarchy is defined recursively, i.e. it is not static.

Managers could also ship packages.

How to do this? What MDX Script do I need to properly SUM'ing NumberOfPackagesPerOrder by summing these only after DISTINC' ing these by OrderId?

Was it helpful?

Solution

The easiest way to do this is not to use an MDX Script at all but to implement a many-to-many relationship. Based on what you've described, I can't give you a complete description of what's necessary but I mocked up an example and got correct values. I have a worker dimension set up with hierarchical relationships to managers as you describe - using a parent-child structure. I have a fact table with worker, order id, and number of packages. In this last case, the number of packages isn't really necessary - it should be ignored. I added a second fact table to have distinct values for order ID and number of packages.

Then in the SSAS project, I have two dimensions - one for worker and one for order ID.

Then I create a cube with two measure groups - one for each fact table. The one with worker and order ID can use the number of packages or a count of rows - it doesn't matter, but the measure needs to be hidden. It's just used as an intermediate fact table for the many-to-many.

Then the fact table that has the distinct order id and number of packages is the second measure group. You can add an order count and use the number of packages as two separate measures in this measure group.

On the dimension usage tab, Worker and Order ID have a relationship to the intermediate fact table (worker and order ID columns in that fact table). Order ID also has a regular relationship to the fact table with order ID and number of packages. Worker has a many-to-many relationship to this fact table (the one with unique order ID) using the other fact table as the intermediate measure group.

When you set it up this way, your order count and number of packages roll up correctly by worker and by manager at all levels of the hierarchy. No MDX required.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top