SQL Server Analysis Services 中的一对多关系

发布于 2024-11-05 19:14:29 字数 1505 浏览 0 评论 0原文

我有这些表:

  1. DimDate(PK:DateKey,其他属性)

  2. FactActivationCodes(PK:ActivationCode,IssuedDateKey(FK 到 DimDate)

  3. FactExpirations(PK:ActivationCode + ExpirationType,FK:ActivationCode 到 FactActivationCodes)

我设置了措施计算

  1. Issued Count(FactActivationCodes 中的行数)

  2. Expired Count(FactExpirations 中不同 ActivationCodes 的计数)

这个想法是,FactActivationCodes 有一个激活码,并带有发布日期。激活码可能会年复一年地过期(然后续订),因此它会有一行过期信息。在 FactExpirations(每年一次)中,

我在表中放入了一些测试行;我在 FactActivationCodes 中放入了 3 行(每行都有不同的 IssuedDate),而在 FactExpirations 中只放入了 2 行。当我浏览多维数据集时,我正在查看列上的发行计数和行上的发行日期(维度),它看起来像这样:


                   Issued Date 
January 2008         1 
February 2008        1 
March 2008           1 

但是,当我添加过期计数时,我希望看到 '由于两个事实表之间存在一对多关系,“过期列”仅与与“激活代码”匹配的列进行计数:


                    Issued Date   Expired Date 
January 2008            1             1  
February 2008           1             1 
March 2008              1             0 

但是,我像这样对所有内容进行交叉联接,其中包含过期的总数:



                    Issued Date   Expired Date 
January 2008            1               2 
February 2008           1               2 
March 2008              1               2 
April 2008                              2 
May 2008                                2 
June 2008                               2 

并且从此,对于我的日期维度中的每个日期条目...我想我没有正确处理关系...我怎样才能获得预期的结果?

I have these tables:

  1. DimDate (PK: DateKey, other attributes)

  2. FactActivationCodes (PK: ActivationCode, IssuedDateKey (FK to DimDate)

  3. FactExpirations (PK: ActivationCode + ExpirationType, FK: ActivationCode to FactActivationCodes)

I set up measures that count the number of rows in

  1. Issued Count (count of rows in FactActivationCodes)

  2. Expired Count (count of distinct ActivationCodes in FactExpirations)

The idea is that the FactActivationCodes has one activation code, with a date when it was issued. The activation code can get expired year after year (and then renewed) so it would have a row for expiration in FactExpirations (one each year)

I put some test rows in the tables; I put 3 rows in FactActivationCodes (different IssuedDate for each) , and only 2 in FactExpirations. When I browse the cube, and I am looking at the count of Issued on columns, and the Issued Date (dimension) on rows, it looks like this:


                   Issued Date 
January 2008         1 
February 2008        1 
March 2008           1 

But then, when I add the Expired Count, I was hoping to see the 'expired column' count with only the ones that match the 'Activation Code' like so, because of the one to many relationship between the two fact tables:


                    Issued Date   Expired Date 
January 2008            1             1  
February 2008           1             1 
March 2008              1             0 

But instead, I a cross join of everything like so, with the totals of expired:



                    Issued Date   Expired Date 
January 2008            1               2 
February 2008           1               2 
March 2008              1               2 
April 2008                              2 
May 2008                                2 
June 2008                               2 

And onwards, for every date entry in my Date Dimensions... I guess I'm not doing the relationship correctly... how can I get the expected result?

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

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

发布评论

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

评论(1

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