有没有办法在 SSAS 中计算 MODE?我看到 Microsoft 为 Median、AVG、Max 和 Min 提供了函数,但没有为 Mode 提供函数。我是否需要在 .net 中编写用户定义的函数来实现这一点,还是有更简单的替代方法?
问问题
1769 次
3 回答
1
我可以看到两种可能的选择。创建一个 .Net 存储过程是其中之一,但调用这些过程会产生一些开销,因此您不希望在太多单元格上运行 Mode 函数。
如果您需要操作的不同值的数量不是太多,则另一个选项是创建一个具有基于该数字的属性的维度。然后,您可以创建一个行计数度量并通过在具有数值的维度上执行 TOPCOUNT(... ,1) 来获取模式。
于 2010-02-23T04:15:08.180 回答
0
How about creating a fact dimension (Degenerate dimension) of the numbers you are interested in the mode of, then using that against a count of rows, take the Top Count of 1?
Or are you after a more general MDX calculation that you could use for may scenarios?
于 2010-02-25T16:17:27.903 回答
-1
这应该这样做:
create table #temp (value int)
insert into #temp (value) values (1)
insert into #temp (value) values (1)
insert into #temp (value) values (1)
insert into #temp (value) values (2)
insert into #temp (value) values (2)
insert into #temp (value) values (3)
insert into #temp (value) values (3)
insert into #temp (value) values (3)
insert into #temp (value) values (3)
insert into #temp (value) values (3)
insert into #temp (value) values (3)
insert into #temp (value) values (4)
select value from (select top 1 count(*) as counts, value from #temp group by value order by count(*) desc) as myTemp
于 2010-01-12T18:44:03.397 回答