MDX 计算度量 - 开始日期和结束日期之间的计数

发布于 2025-01-08 02:18:47 字数 486 浏览 5 评论 0原文

我有一个维度“公司”,其中包含成员“CompanyName”和度量值组“CompanyMembership”,其中包含度量值“StartDate”和“EndDate”。如何计算某一日期、某月或某年拥有会员资格的公司数量?我还有一个用户层次结构 Date.Calendar (就像 Adventure Works 中的那样)。

如果当前会员的日期代表一个月,则会员值将是该月的第一天,我只关心会员资格是否涵盖那一天。如果是一年,会员价值将是一年的第一天,我只关心会员资格是否涵盖这一天。

这是我想要的一些伪代码: sum( if (Measures.StartDate <= Date.Calendar.Value <= Measures.EndDate) then 1 else 0)

我想将 StartDate 和 EndDate 保留在同一事实表行中(不分成两行 - 一行带有StartDate 和 EndDate),但如果没有其他方法,愿意更改架构。

我该如何写这个表达式?

I have a dimension "Company" which has a member "CompanyName" and a measure group "CompanyMembership" which has measures "StartDate" and "EndDate". How do I count the number of companies that have membership for a date or month or year? I also have a user hierarchy Date.Calendar (like the one in Adventure Works).

If the date current member represents a month the member value will be the first day of the month and I only care if the membership covers that day. If a year the member value will be the first day of the year and I only care if the membership covers that day.

Here is some pseudocode for what I would like:
sum( if (Measures.StartDate <= Date.Calendar.Value <= Measures.EndDate) then 1 else 0)

I would like to keep StartDate and EndDate in the same fact table row (not split into two rows - one with StartDate and one with EndDate) but would be willing to change the schema if there's no other way.

How can I write this expression?

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

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

发布评论

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

评论(1

£噩梦荏苒 2025-01-15 02:18:47

我没有在您当前的架构中执行此操作的方法,但您确实应该考虑将成员资格设置为时间维度。这就需要回答“这家公司在这一天是会员吗?”容易多了。

I don't have a method for doing this in your current schema, but you should really consider making Membership a time dimension. That would make answering "was this company a member on this date?" much easier.

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