空值的总和和平均值 SQL Server 2008 Analysis Services
我想我有一个简单的问题,但我用谷歌搜索但找不到解决方案。我有一个包含 MeasureA、MeasureB 和 MeasureC 的多维数据集。并非所有三个度量值都具有每个记录的值,有时它们可以为空,这取决于它是否适用。
现在,对于我的总计,我需要求平均值,但平均值不得考虑空值。任何帮助将不胜感激。当我查看度量时,空值显示为零。
I have a simple problem, I think, but I have googled and can't find the solution. I have a cube that has MeasureA, MeasureB and MeasureC. Not all three measures have values for each record, sometimes they can be null, it's depending if it was applicable.
Now for my totals, I need to average but the average must not take nulls into account. Any help will be much appreciated. When I view the measures, the null values show as zeros.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么不使用 AVG() 函数来计算平均值?
例如:
([MEASURES].[MEASUREA] + [MEASURES].[MEASUREB] + [MEASURES].[MEASUREC]) / 3
当然,只有当该平均值仅包含 3 个小节时,这才有效。如果您需要对一组进行评估,我只会真正使用 AVG() 函数:
http://msdn.microsoft.com/en-us/library/ms146067。 ASPX
Why not compute the average without the use of the AVG() function?
For example:
([MEASURES].[MEASUREA] + [MEASURES].[MEASUREB] + [MEASURES].[MEASUREC]) / 3
Of course, this only works if this average will only ever consist of 3 measures. I would only really use the AVG() function if you needed to evaluate over a set:
http://msdn.microsoft.com/en-us/library/ms146067.aspx
默认情况下,SQL Server 会忽略空值 - 因此您会收到消息 -
警告:空值已被聚合或其他 SET 操作消除。
示例:
By default, SQL Server ignores nulls - hence the message you get -
Warning: Null value is eliminated by an aggregate or other SET operation.
Example:
您可以使用 NonEmpty() MDX 函数来包装要平均的集合吗?
http://msdn.microsoft.com/en-us/library/ms145988。 ASPX
Can you use the NonEmpty() MDX function to wrap the sets that you are averaging out?
http://msdn.microsoft.com/en-us/library/ms145988.aspx
对于每个度量,在其属性中转到源列设置并选择 NullProcessing="Preserve",然后该度量将返回 NULL 而不是 0
For each measure, in its Properties go to the source column settings and choose NullProcessing="Preserve", and then the measure will return NULL and not 0