SSAS - 一段时间内发生的事实

发布于 2024-09-24 07:46:50 字数 373 浏览 0 评论 0原文

我真的不知道如何处理一段时间内发生的事实。我通常处理特定日期发生的事实。

明确地说,我的事实有一个开始日期和一个结束日期。因此,假设我的开始日期是 01/01/2008,结束日期是 01/01/2011。我需要获取 2009 年发生的事实和今年发生的事实的数量。同样的事实可能在这两年都发生过。确定事实是否属于 2009 年的方法是检查 12/31/2009。

我正在考虑使用日期范围的 StartDate 和 EndDate 维度(因此从 StartDate 维度的第一个日期到 2009 年 12 月 31 日,以及从 2009 年 12 月 31 日到 EndDate 维度的最后一个日期)。我会加入其中。

我试过了,确实有效,但是速度真的很慢。

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄凉少年不暖心 2024-10-01 07:46:50

我找到了我想要的解决方案。大卫和克里斯的答案!这就是我想要实现的目标,但我缺少 MDX 语法:

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)

非常简单。我认为我的问题不清楚,这就是为什么我得到不同的答案;-)

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

A君 2024-10-01 07:46:50

您始终可以使用具有两个时间维度的日期范围,例如:

选择 [开始日期].[年份].[2009]:[结束日期].[年份].[2010]上 0
来自立方体

如果我正确理解了这个问题。两个时间维度应该可以很好地协同工作。我在工作中正在做的一个项目中有两个,它们一起工作得相当快。确保在多维数据集的维度使用部分中设置它们,以便可以区分两个日期。

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.

若言繁花未落 2024-10-01 07:46:50

您只需要一个日期维度 DimDate。您的事实表可以有 2 个 DimDate 外键,一个用于开始日期,一个用于结束日期。

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

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

要获取 2009 年的所有事实,请使用

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文