To start with I’d like to elucidate what a Position-playing dimension really means. Then I’ll categorical the best way you possibly can implement it in a SSAS tabular mannequin.
If you hyperlink a dimension to a reality desk a number of instances for logically distinctive roles you’re utilizing a role-playing dimension.
The important thing factors are:
1. You might be linking a reality desk to a dimension a number of instances. The relationships are outlined by linking a number of overseas keys within the reality desk to a single key within the dimension desk.
2. Every linkage represents a single position or idea
The preferred role-playing dimensions are DimDate and DimTime. Do you wish to see how one can implement Position Enjoying Dimensions in Energy BI, Click on right here and right here.
NOTE: The pattern is from Microsoft “AdventureWorksDW” for SQL Server 2012 and may be totally different from your personal knowledge warehouse design.
As an example, in a gross sales system that you’ve got one thing like FactInternetSales reality desk which has a number of hyperlinks, or relationships, to a DimDate or DimAddress for distinct ideas like “Order Date”, “Ship Date” and “Due Date”.
As you see, all the above columns clearly characterize totally different meanings of date. Within the knowledge warehouse design you’ll see one thing like this:
Though that is completely OK within the relational database layer, however, this kind of relationship is NOT permitted within the tabular mannequin, so what ought to we do?
Let’s take a look on the tabular mannequin in SQL Server Information Instruments (SSDT) and see the way it seems after we import the mannequin straight from SQL Server knowledge supply.
· Open SSDT and create a brand new evaluation companies tabular venture (I assumed you understand how to create a brand new venture in SSDT)
· Click on on “Import From Information Supply”, then choose “Microsoft SQL Server” then click on “Subsequent”
· Enter the server identify and choose “AdventureWorksDW” from the database checklist then click on “Subsequent”
· Entre impersonation data and click on “Subsequent”
· Click on “Subsequent”
· Right here you possibly can choose all tables and views you could import into your tabular mannequin. In our pattern we simply want “FactInternetSales” and “DimDate” tables. So tick the “FactInternetSales” and “DimDate” tables after which click on “End”.
· Shut the “Desk Import Wizard”
· Swap to “Diagram View”. As you possibly can see there is only one Energetic relationship between DimDate and FactInternetSales tables and each different relationships are Inactive which means you can not immediately use the imported DimDate for all three functions you could cowl the “Order Date”, “Ship Date” and “Due Date”. Which means you can not slice and cube a single measure with all roles on the similar time, which in our instance they’re “Order Date”, “Ship Date” and “Due Date”. I clarify extra later on this publish.
1. Importing DimDate into your tabular mannequin a number of instances:
In our pattern we have to import it 3 times to cowl “Order Date”, Ship Date” and “Due Date”.
a. Delete the inactive relationships
b. Double click on on the DimDate desk identify to rename it to a person pleasant identify. Title it “Order Date”.
c. To make our pattern extra untestable I created a brand new hierarchy named “Order Date Particulars” which incorporates “CalendarYear”, “EnglishMonthName” and “FullDateAlternateKey”. A additionally renamed the columns to make the extra person pleasant to “12 months”, “Month” and “Full Date”. As well as, I set all different columns within the DimDate desk to “Conceal from Shopper Instruments”. I additionally renamed the “FactInternetSales” desk to “Web Gross sales”.
d. We now have efficiently setup the “Order Date” date and now we have to import the DimDate desk once more to assist the “Ship Date”. To take action, from the “Mannequin” menu choose “Present Connections…”
e. Click on “Open”
f. Click on “Subsequent”
g. Choose DimDate from the checklist once more and click on “End”. This course of will import the DimDate desk to the mannequin once more. We’ll then set it as much as cowl “Ship Date”. To take action, hyperlink “ShipDateKey” from “Web Gross sales” desk to “DateKey” from “DimDate” desk.
h. Now repeat the above sections from b to g however, identify the “DimDate” desk “Ship Date”. Repeat the above sections once more so as to add “Due Date” to the mannequin.
i. We’re carried out and we will merely slice and cube based mostly on all the above dates.
j. Because the tabular mannequin doesn’t detect the measures robotically we have to outline a minimum of a measure to have the ability to check the answer. To take action swap to “Grid View” and choose the “Web Gross sales” then outline a measure for “Complete Gross sales Quantity”. To take action simply click on on measures part beneath the “SalesAmount” column then click on the Sigma () button from the toolbar. Then rename the created measure to “Complete Gross sales Quantity”.
ok. Now we will check the answer by deciding on “Analyze in Excel” from “Mannequin” menu
l. Tick “Complete Gross sales Quantity” and “Due Date Particulars” hierarchy. You possibly can drilldown to month and day ranges.
m. You are able to do the identical for every of the opposite dates or you may make a mix of dates in case you want such a report.
2. Creating a number of SQL Server views within the database:
In our instance, in “AdventureWorksDW” database, we create three views for every position (Order Date, Ship Date, Due Date). We create these views on prime of the prevailing DimDate with totally different names resembling the three totally different roles. Then we import these views into our tabular mannequin and hyperlink every of them to the “Web Gross sales” desk utilizing the suitable overseas key. As the entire course of is similar as what we’ve carried out beforehand within the first answer, I’m not going to elucidate it once more. So, on the finish of the day, we can have one thing like this within the database:
Now you can import the above views to your tabular as an alternative of importing the entire DimDate desk a number of instances. This can scale back the database measurement and it’s a bit simpler to know. Nonetheless this answer is similar to the primary answer . Mainly the structure is kind of the identical, however, the best way we handle the tables is a bit totally different.
And the identical leads to Excel:
3. Creating a number of measures:
The third answer, which might be the very best for almost all of use circumstances, is totally the alternative of what we’ve carried out thus far. Nicely, I can say that the structure is kind of totally different. On this answer we DO NOT take away the Inactive Relationships and furthermore, we DO NOT import a number of copies of Date dimension.
What we must always do on this case is to create new measures for every position which implies we can have the next three measures in our instance:
1- Complete Gross sales Quantity by Order Date
2- Complete Gross sales Quantity by Ship Date
3- Complete Gross sales Quantity by Due Date
What we’re doing on this answer is that we handle to make use of the connection which is related to the roles. To try this we simply have to implement the info mannequin to activate the connection we want. We are able to simply energetic and inactive relationship in DAX utilizing USERELATIONSHIP operate. The USERELATIONSHIP operate, disables all energetic relationships first, then prompts a desired relationship. USERELATIONSHIP operate can be utilized as part of different features that take filters as arguments. Which means we at all times use USERELATIONSHIP as part of a CALCULATE operate (or different features that settle for filter arguments). Due to this fact, the above three measures will appear to be beneath:
1- Complete Gross sales Quantity by Order Date:= SUM(‘Web Gross sales'[Sales Amount])
2- Complete Gross sales Quantity by Ship Date := CALCULATE(SUM(‘Web Gross sales'[Sales Amount]), USERELATIONSHIP(‘Date'[DateKey], ‘Web Gross sales'[ShipDateKey]))
3- Complete Gross sales Quantity by Due Date := CALCULATE(SUM(‘Web Gross sales'[Sales Amount]), USERELATIONSHIP(‘Date'[DateKey], ‘Web Gross sales'[DueDateKey]))
As you possibly can see within the first measure we haven’t used USERELATIONSHIP. The rationale is that the measure makes use of the connection which is energetic by default within the mannequin, due to this fact we don’t have to implement it once more. The opposite two measures alternatively are implementing related relationships for use inside the measures.
Lastly, right here is the way it seems like while you analyse the mannequin in Excel:
Every of the three options mentioned above have execs and cons.
Professionals of the primary two options, importing a number of Date dimensions:
1- In case your mannequin is a small mannequin then it might be faster to develop the mannequin
2- It could be simpler for the tip person to have totally different Date choices. You’ll have separate slicers within the visualisation layer for every position.
3- You possibly can have only one measure and slice and cube it by totally different roles individually
Cons:
1- In case your mannequin just isn’t small and you’ve got way more position taking part in dimensions to handle you then’ll find yourself importing these dimensions a number of instances which isn’t environment friendly
2- Having a lot of totally different position taking part in dimensions all around the mannequin might be actually complicated for the tip person and you’ll actually need to spend extra time/cash to coach the tip customers
3- You devour extra storage and reminiscence which is once more not that environment friendly
Professionals of the final answer, creating a number of measures:
1- You should utilize all of the roles side-by-side as you actually have a separate measure for every position
2– You aren’t importing a number of copies of the roles, as an illustration, you might have only one Date dimension that can be utilized to slice and cube your entire measures throughout the entire mannequin
3- It’s extra environment friendly by way of storage and reminiscence consumption
4- Your mannequin is way more tidy while you don’t have a number of roles all around the mannequin
Cons:
1- In giant fashions with a lot of totally different roles, creating a lot of totally different measures to assist totally different roles can be time consuming and in addition a bit onerous to take care of
2- The measure names are getting lengthy
3- Having a lot of totally different measures that look very related is usually a bit complicated for the tip person
All carried out!