非时间维度中最后一个子级的计算成员?

发布于 2024-12-15 09:08:17 字数 433 浏览 2 评论 0原文

在 SSAS 多维数据集中,如何为非时间维度创建聚合为 LastChild 的度量?

源数据在任何一天都有相同业务记录的多个版本。时间维度的粒度是 DATE,而不是秒和秒。毫秒。

事实记录具有时间戳和增量(身份)主键。实际上,我想要的是将度量计算为给定日期所有编辑的最后一个值。

到目前为止,我看到的选项属于以下两类之一:

  • 生成精确到秒的时间维度。这将导致非常大且低效的时间维度。

或者

  • 隐藏度量并将其替换为计算度量,这些度量根据主键查找任何给定日期的最后一个值。这样既麻烦又效率低。

是否有最佳点或替代技术来解决这个问题?

数据的自然层次结构是:

  1. 业务键
  2. 记录时间戳(链接到时间维度)
  3. 代理键

In a SSAS cube, how do I create measures that are aggregated as LastChild for a non-time dimension?

The source data has many versions of the same business record on any given day. The time dimension has a granularity of DATE, not seconds & milliseconds.

The fact records have a timestamp and an incremental (identity) primary key. In effect, what I want is to calculate a measure as being the last value for all edits on a given date.

The options I've seen so far fall into one of two categories:

  • Produce a time dimension that goes down to seconds. This would result in a very large and inefficient time dimension.

OR

  • Hide the measures and replace them with calculated measures that look up the last value for any given date based on the primary key. This is cumbersome and less efficient.

Is there a sweet spot or alternative technique to solve this problem?

The natural hierarchy of the data is:

  1. Business Key
  2. Record Timestamp (links to TIME dimension)
  3. Surrogate Key

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

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

发布评论

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

评论(1

酒中人 2024-12-22 09:08:17

不,您绝对无法创建没有时间维度的 latChild 属性:

在此处输入图像描述

您可以做的是创建查询在 DSV 上为您提供最后一个子值并使用它来创建度量值组。示例:

脚本:

create table dim(
id int not null primary key,
name varchar(50))
insert into dim values (1,'one'),(2,'two')

create table fact(
id int not null primary key,
dimId int not null,
value numeric (12,3),
constraint fk_fact_dim foreign key(dimId) references dim(id))

insert into fact values (1,1,5)
insert into fact values (2,1,3)

insert into fact values (3,2,10)
insert into fact values (4,2,20)

非常简单的脚本,用于创建暗淡表和事实表。这是一个简单的选择,在我认为你想要的结果之后,因此 3 和 20 将是​​基于维度 ID 的最后一个值:

构建非常简单,只需右键单击您的 DSV 并添加一个新的命名查询并通知查询创建您的最后一个值。在我的例子中是:

select dimId, 
(select top 1 value from fact where dimId=F.dimId order by id desc) as lastValue
from fact F
group by dimId 

创建一个逻辑主键并将其链接到维度表:
在此处输入图像描述

在您的多维数据集中,右键单击任意空白区域,选择“显示所有表格”并添加新表格。

在您的多维数据集中创建一个新度量作为“无聚合”,因为您已经聚合了查询:

在此处输入图像描述

结果:

在此处输入图像描述

No, you absolutely cant create a latChild attribute without a time dimension:

enter image description here

what you can do is create a query on your DSV to give you the last child value and use it to create a measure group. Example:

Script:

create table dim(
id int not null primary key,
name varchar(50))
insert into dim values (1,'one'),(2,'two')

create table fact(
id int not null primary key,
dimId int not null,
value numeric (12,3),
constraint fk_fact_dim foreign key(dimId) references dim(id))

insert into fact values (1,1,5)
insert into fact values (2,1,3)

insert into fact values (3,2,10)
insert into fact values (4,2,20)

very simple script that creates a dim and a fact table. Here is a simple select and after the result I think you want, so 3 and 20 would be the last values based on the Dimension's ID:

enter image description here

to build that is very simple, just right click on your DSV and add a new named query and inform the query to create your last value. In my case is:

select dimId, 
(select top 1 value from fact where dimId=F.dimId order by id desc) as lastValue
from fact F
group by dimId 

create a logical primary key and link it to the dimension table:
enter image description here

and on your cube, right click any blank area, select "show all tables" and add your new table.

And on your cube create a new measure as "no aggregations" because you have already aggregated your query:

enter image description here

Result:

enter image description here

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