Setting up Many to Many in SSAS 2008 Cube

Who is online?  0 guests and 0 members
Home  »  Articles  »  Setting up Many to Many in SSAS 2008 Cube

Setting up Many to Many in SSAS 2008 Cube

change text size: A A A
Published: 1/26/2010 by  MikeDavis  - Views:  [3588]  

This article will cover creating a Many to Many relationship in analysis services. It is assumed you already know how to create dimension and measure groups in Analysis services and have a basic understanding of analysis services. I will be writing more basic articles on analysis services to help the ones that are new. Check my other articles and blogs for this.

In some situations the fact table in your data warehouse will have a many to many relationship with a dimension. This situation calls for the use of a bridge table and setting up a many to many relationship between the fact and dimension with the bridge. I have created a miniature data warehouse example to simplify the issue and show the steps on how to set this up quickly. First let's discuss why we would have a many to many relationship.

Let's say our fact table is a table of sales, and each sale can have multiple sales reps. If several sales reps worked on the sale then they all get credit for the order. They all may get a percentage of the sale also. I will show you how to handle this later.

First let's take a look at the tables. I have trimmed these down to just the needed columns to simplify the example.

Here is the Fact Sales Table. Notice there are only 5 sales on the table. But each sale can have several sales reps associated with it. Notice there is no SalesRepSk. This is because no one sales rep ID would cover all the sales reps. The order id will tie to the bridge table to tell us who the sales reps were on each sale.

Setting up Many to Many in SSAS 2008 Cube

Here is the Sales Rep table. Again stripped down for simplicity.

Setting up Many to Many in SSAS 2008 Cube

 

Here is the Sales Rep Bridge table. Notice this table has an SK that ties it to the sales rep and the order id which ties it to the fact table. Notice how some orders repeat. This is because they have multiple sales reps. For example Order ID 10 has the reps 1, 2, and 3.

Setting up Many to Many in SSAS 2008 Cube

 

This is what the table will look like in Analysis Services in a cube. Notice the direction of the foreign keys from the sales rep bridge. Notice the fact sales does not tie directly to the sale rep dimension table. I have a date dimension added also. This is just a basic date dimension with a regular relationship to the fact sales. I will explain the SalePercent on the bridge in a moment.

Setting up Many to Many in SSAS 2008 Cube

 

Once you have the tables and regular dimensions set up you will need to add the fact table as a dimension. Right click on the dimension folder in the solution explorer and select new dimension. Select the fact table as the table to use.

Setting up Many to Many in SSAS 2008 Cube

 

Then you will add it to the cube as a dimension. In the bottom left right click on the cube in the dimension window and select Add Cube Dimension. Select Fact Sales as the dimension. The only attribute I am going to show is the order ID. This is also known as a degenerate dimension.

Setting up Many to Many in SSAS 2008 Cube

 

Setting up Many to Many in SSAS 2008 Cube

 

Next we are going to add the sales rep bridge as a new measure group. Right click on the cube in the measure window and select new measure group. Select the sales rep bridge as the table. You can hide all of the attributes. We do not need to see these in the cube.

Setting up Many to Many in SSAS 2008 Cube

 

Now we will set up the many to many relationship between the tables. Click on the dimension usage tab. Notice the field next to Sales rep under fact sales is blank. Click on the button next to it and select many to many as the relationship type. Select Sales Rep Bridge as the intermediate measure group. Afterwards you will see a many to many symbol in the dimension relationship field.

Setting up Many to Many in SSAS 2008 Cube

 

Now process and deploy the cube. Go to the browser tab and you will now be able to see the orders with the multiple sales reps.

Setting up Many to Many in SSAS 2008 Cube

 

But wait there's more. What if each sales rep has a different percentage of the sale. Maybe a different commission percentage. The only place it would make since to place the percentage would be on the bridge table. Because the number can be different for each order and for each sales rep. Notice I have added this column to the sales rep bridge table. Each order the percentage will add up to 100%.

Setting up Many to Many in SSAS 2008 Cube

 

Now you can add this measure to the sale rep bridge measure group.

Setting up Many to Many in SSAS 2008 Cube

 

Go back to the browser and reconnect. Drag down the percentage from the measures. Now you can see the sales rep percentage for each sales rep for each sale. In this example you can see Devin has 25% of order 10 and 100% of order 12. Some sales may have a single rep and other multiple.

Setting up Many to Many in SSAS 2008 Cube

This is a complex situation. I hope I simplified it for you. Let me know if you have any questions.

 
0
/5
Avg: 0/5: (0 votes)

Comments (20)

Slava
Slava said:
Good job. Thank Mike
2/2/2010
 · 
 
by
tinocash
tinocash said:
Very nice article.
2/2/2010
 · 
 
by
tinocash
tinocash said:
Very nice article. It’s quite a bit more thorough that other blog articles I’ve found on the same subject.
2/2/2010
 · 
 
by
bumpagab
bumpagab said:
Great article. This situation has come up for me before and I'm glad to know a solution. I muddled through it, but not as gracefully as this.
2/9/2010
 · 
 
by
ScottA
ScottA said:
Thanks for the article. Do you think that it is important to limit these types of dimensions as much as possible because of scalability concerns? Or, is it not much different than a regular dimension?
2/19/2010
 · 
 
by
mikedavis
mikedavis said:
It is not much different than other dimensions. I have not seen any issues with scaling this out. The partitions and aggregations help a lot with that. It is hard to avoid these when there truly is a many to many relationship.
2/19/2010
 · 
 
by
ScottA
ScottA said:
I have setup a dimension as described here and have a case where I sometimes do not have a record in the bridge table. I would like to have None as a default value if possible. I have set the "Unknown Member" and "Unknown Member Name" for the dimension (DimSaleReps in the example) but it doesn't seem to have any impact. Are there any solutions other than forcing a record into the bridge table for every row in my Fact table? Thanks.
2/25/2010
 · 
 
by
mikedavis
mikedavis said:
Scott A, You should post this question in the forum so others may answer. But my answer: Create an unknown row on the bridge table with an id of zero. When filling the fact table, use a lookup to see if the row does not exist. Then use a derived column to set the fact SK value to zero if it does not exist on the bridge. If the SK on the fact table is being used to map to another dimension then you will have to make sure it does not change that. You may need to duplicate the SK on the fact table.
2/25/2010
 · 
 
by
ScottA
ScottA said:
Since the bridge table is foreign keyed based on the OrderID, I'm not sure how the id zero comes in. I did go ahead and post the question in the Analysis Services forum.
2/25/2010
 · 
 
by
dtvam
dtvam said:
Good one
3/29/2010
 · 
 
by
Daniel
Daniel said:

I am facing a similar challenge right now.  This article provides a clear path to follow.  Thanks

6/4/2010
 · 
 
by
siddu2010
siddu2010 said:

great  article ,

i have a similar situation ,but what if i want to query the same   with some more  attributes from other dmensions which have normal 1 to many relaton ship with the exstng fact table,

 

i have report which needs different comissions  and also some more other attributes from other dimnesions which have 1 to  many relatonships with the exsting fact table

2/19/2011
 · 
 
by
MikeDavis
MikeDavis said:

Siddu, Check of the many to many revolution white paper. It shows how to built very complex many to many relationships.

http://www.sqlbi.eu/Portals/0/Downloads/M2M%20Revolution%201.0.93.pdf

2/21/2011
 · 
 
by
ranjani_v
ranjani_v said:
Great article Mike, Can you please expalin how you have added the salespercent in the Bridge .I mean on what based did you added.
3/21/2012
 · 
 
by
MikeDavis
MikeDavis said:
Each sales person gets a percent of the commision on a sale, So each sale has a unique value for each sales person. The same query used to get the bridge table data can simply have the percent added to it also.
3/21/2012
 · 
 · ranjani_v likes this.
 
by
ranjani_v
ranjani_v said:
I'm new to your forum and also to microsoft BI world.Please can you send the sample query how you have calculated using above table.
3/21/2012
 · 
 
by
MikeDavis
MikeDavis said:
It was a join between the source tables. The one with the sales and the one with the sales people. I do not have the query any more, it was a client a while back.
3/21/2012
 · 
 
by
ranjani_v
ranjani_v said:
Thanks! a lot Mike.I got some idea ,I'll try
3/21/2012
 · 
 
by
ranjani_v
ranjani_v said:
Based on above table I tried creating the Percentages but it didn't get me exact values.Anything I need to add while joining the three tables in order to get exact percentage values.
3/21/2012
 · 
 
by
MikeDavis
MikeDavis said:
Sorry I don't know, it would based on your source system.
3/22/2012
 · 
 
by

Most Recent Articles