SSAS - Facts that happened over a time range

流过昼夜 提交于 2019-12-08 06:22:26

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 ;-)

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.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!