how to connect generated time dimension with datetime field, ssas - ssas

I have a datetime field in my fact table, and I want to group and filter by it, so I created a time dimension and ssas generated a table for it that has a date without time primary key.
What is the right way to connect this generated table to my field, create a view and calculate there additional date with empty time? or there are any other more simple way, maybe using some hierarchies or something? Sorry for probably very simple question its just my second day with analysis servises

How do you fill your fact table. The usual way to this is in the ETL process.
You have a time dimension DIM_Date
With the columns Date_ID, Year, Month, Weekday
Then you should have a fact table FACT_Sales
With the columns Date_ID, Product_ID, Customer_ID, value
When filling the fact table with your ETL-Tool. Let's assume it is SSIS. You do a lookup in the date dimension and set the surrogate key in the facts (Date_ID) correspondingly.
If the tables are allready there. You can use a computed column in the SSAS Data Source View and set your foreign key relationship via drag and drop.

Related

Multiple Joins from one Dimension Table to single Fact table

I have a fact table that has 4 date columns CreatedDate, LoginDate, ActiveDate and EngagedDate. I have a dimension table called DimDate whose primary key can be used as foreign key for all the 4 date columns in fact table. So the model looks like this.
But the problem is, when I want to do sub-filtering for the measures based on the date column. For ex: Count all users who were created in the last month and are engaged in this month. This is not possible to do with this design, coz when I filter the measure with create date , I can’t further filter for a different time window for engaged date. Since all the connected to same dimension, they are not working independently.
However, If I create a separate date dimension table for each of the columns, and join them like this then it works.
But this looks very cumbersome when I have 20 different date columns in fact table in real world scenario, where I have to create 20 different dimensions and connect them one by one. Is there any other way I can achieve my scenario w/o creating multiple duplicated date dimensions?
This concept is called a role-playing dimension. You don't have to add the table to the DSV or the actual dimensions one time for each date. Instead add the date once, then go to the dimension usage tab. Click Add Cube Dimension, and then choose the date dim. Right-click and rename it. Then update the relationship to use the correct fields.
There's a good article on MSSQLTips.com that covers this topic.

Customer Dimension as Fact Table in Star Schema

Can Dimension Table became a fact table as well? For instance, I have a Customer dimension table with standard attributes such as name, gender, etc.
I need to know how many customers were created today, last month, last year etc. using SSAS.
I could create faceless fact table with customer key and date key or I could use the same customer dimension table because it has both keys already.
Is it normal to use Customer Dimension table as both Fact & Dimension?
Thanks
Yes, you can use a dimension table as fact table as well. In your case, you would just have a single measure which would be the count - assuming there is one record per customer in this customer table. In case you would have more than one record per customer, e. g. as you use a complex slowly changing dimension logic, you would use a distinct count.
Given your example, it is sufficient to run the query directly against the Customer dimension. There is no need to create another table to do that, such as a fact table. In fact it would be a bad idea to do that because you would have to maintain it every day. It is simpler just to run the query on the fly as long as you have time attributes in the customer table itself. In a sense you are using a dimension as a fact but, after all, data is data and can be queried as need be.

Creating relationship between 2 tables in SQL

I have these 2 tables and I need to create a relationship between them so that I can import them into SSAS Tabular and run some analysis.
The first table has RollingQuarter(Moving Quarter) data. The second is a basic Date table with Date as PK.
Can anyone suggest ways to create a relationship with these?
Ill be using SQL Server 2012.
I could re-create a new date table also.
I think you may have a rough time finding a relationship with these tables.
Your top data table is derived data. It's an average over three months, reported monthly. The Quantity column applies to that window, not to a particular date like all of the stuff in the second table. So what would any relationship really mean?
If you have the primary data that were used to calculate your moving average, then use those instead. Then you can relate dates between the two tables.
But if your analysis is such that you don't need the primary data for the top table, then just pick the middle of each quarter (March 15th 2001 for the first record) and use that as your independent variable for your time series on the top. Then you can relate them by that.

How should one define a second date hierarchy in SSAS?

I have a time table and a sales fact table with multiple dates (order received date, ship date).
I want to define a hierarchy on the order received date and another hierarchy on the ship date.
The cube editor in visual studio allows me to define multiple relationships on these table, but I don't see a way in the hierachy editor to define which relationship to use for the hierarchy.
Am I missing something, or am I supposed to insert the time table into the model twice, which single relationships on each?
Thanks, --sw
Wouldn't this be where you use role-playing dimensions? So you have your date dimension, with all it's hierarchies, then you join that again to the fact table on the ship date, and now you have a "Date (Ship Date)" dimension with all the Date dimension hierarchies.
http://www.msbiguide.com/2012/05/role-playing-dimensions-in-ssas/
http://msdn.microsoft.com/en-us/library/ms174487(v=sql.90).aspx
http://kimballgroup.forumotion.net/t1165-role-playing-dimensions
You only create the Date dimension once by the way, it just gets a new alias in the cube for each time it role-plays.

Calculate date and time key in fact table using existing date time field

I have date time field in a fact table in the format MM/DD/YY HH:MM:SS (e.g 2/24/2009 11:18:47 AM) and I have seperate date and time dimension
tables. What I would like ask is that how I can create date key and time key in the fact table using the date time field so that I can join the
date and time dimension.
There are alot of reference for creating seperate date and time dimension and their benefit but I could not find how to create date and time keys
in the fact table using existing date time field.
I have also heard that having date time field in fact table has certain benefit. If so, what would you recommend, should I have all three (date key, time key
and date time field) in the fact table. Date key and time key are must to have for me and I am concerned about fact table size if I have date time field
also in the fact table.
Thank you all for any help you can give.
What you need to do (if I understand correctly) is to create two fields in your Fact table:kTime, kDate.
We would always suggest using the primary keys for DimTime and DimDate as having meaning (this being a special case normally Dim tables' promary keys dont have any meaning). So e.g. in DimDate, we would have kDate as primary key with values formatted as YYYYMMDD so that you can order by kDate and it puts them in date order. Then have DimTime table having kTime primary key in the form HHMM or HHMMSS (depending on the resolution you need.
It is best to keep the actual date time field on the fact table as well, as it allows SQL to use its inbuilt date/time functions to do subsetting, but if you extend your Dim tables with useful extra columns : DimDate (add DayOfWeek, IsHoliday, DayNumber, MonthNumber, YearNumber, etc) and DimTime (HourNumber, MinuteNumber, IsWorkingTime), then you can perform very interesting queries very simply.
So to answer your question, "how to create date and time keys in the fact table using existing date time field?" ... as you are loading the data into the fact table, use the inbuilt date/time functions to create separate Date fields and Time fields.
It depends very much on how many rows you expect in your Fact table wether this approach will produce a lot of data, but it is the easiest to work with from a data warehouse point of view.
best of luck!