views:

52

answers:

3

Hi,

I don't really know how to handle facts that happened over a period of time. I sually deal with facts that happened on a specific date.

In clear, my facts have a start_date and an end_date. So, let's say my start_date is 01/01/2008 and my end_date is 01/01/2011. I need to get the number of those facts that happened in 2009 and those that happened this year. The same fact can have happened on both years. The way to determine a fact is part of 2009 is to check for 12/31/2009.

I was thinking about a StartDate and EndDate dimensions, using date ranges (so from the first date of my StartDate dimension to 12/31/2009 and from 12/31/2009 to the last date in my EndDate dimension). I would cross join those.

I tried it, it works, but it's REALLY slow.

Any thoughts?

A: 

You just need one Date dimension DimDate. Your fact table can have 2 foreign keys to the DimDate, one for startdate and one for enddate.

FactTable
{
    FactID int,
    StartDate int,
    EndDate int
    -- Other fields
}

DimDate
{
    DimDateID int,
    Year int,
    Month int,
    Day int,
    -- Other fields if needed
}

To get all facts that fall on the year 2009, use

SELECT f.FactID FROM FactTable f
INNER JOIN DimDate dStart ON dStart.DimDateID = f.StartDate
INNER JOIN DimDate dEnd ON dEnd.DimDateID = f.EndDate
WHERE dStart.Year <= 2009
  AND dEnd.Year >= 2009
David
Okay, that was basically my workaround. But doing so will require me to create queries for current year, last year, last month, etc. and thus generate a measure group per query. I was looking for a way to have a single query (so a single measure group) that I will be able to analyze with a time dimension in my calc script.
Dominic Goulet
I see. So you want a query that generates a report that shows number of facts for every year?
David
I want to be able to display at the same time the current number of facts, the number of facts for last month and the number of facts for last year, same month. I would usually do it in my calc script for a fact that happned at a specific date with an MDX expression, like ([Measures].[Total number of X], [Date].[Year].[2009]). My problem now is that the fact's date is not 2009, but rather 2009 is included between a start date and end date¸in my fact definition.
Dominic Goulet
Think you have > and < the wrong way around. e.g. If something starts in 2009 and finishes in 2010, then it will be missed using the query supplied
adolf garlic
edited. Thanks.
David
So I guess I will just continue to do it with a SQL query instead of a MDX expression.
Dominic Goulet
A: 

You can always use a date range with the two time dimensions like:

Select [start date].[year].[2009]:[end date].[year].[2010] on 0 from cube

If I'm understanding the question correctly. Two time dimensions should work together fine. I have two in a project I'm doing at work and they work rather fast together. Make sure that you set them up in dimension usage section of the cube so you can differentiate the two dates.

Chris
First, it's basically the other way around. I want a specific date to be included between my start and end date, or said otherwise I want (myDate > startDate AND myDate < endDate). Second, you cannot use two different dimensions in a range, or you get an error.
Dominic Goulet
True. you can always use a sub select to pick out one of the ranges.Select [start date].[year].[2009] on 0 from (select [end date].[year].[2009] from [cube])
Chris
A: 

I found the solution to what I wanted. David and Chris for the anwsers tho! Here's what I wanted to achieve, but I was lacking MDX syntax :

SELECT  [Measures].[NumberX] ON COLUMNS
FROM    [MyCube]
WHERE   ([START DATE].[REFDATE].FirstMember:[START DATE].[REFDATE].&[2009-12-31T00:00:00],
        [END DATE].[REFDATE].&[2010-01-01T00:00:00]:[END DATE].[REFDATE].LastMember)

Pretty simple. I think my question was not clear, that's why I got different answers ;-)

Dominic Goulet