SSRS在计算平均值时包括空单元格
团体, 这很难解释,但我正在 SSRS 中构建矩阵报告。我的行包含产品代码,我的列是月份(前 13 个),我的值是相应产品/月的销售单位。我找到了一些客户代码,可以让我将小计更改为平均。但是,对于某些产品,一个月内可能没有售出任何单位,因此单元格为空白。
所发生的情况是,产品代码 XI 在 2009 年 3 月售出 10 件,在 2010 年 1 月售出 1 件,总共 11 件。不是采取 11(售出单位)/ 13(个月),而是采取 11 / 2,因为它只注册 2 个月,因为其他 11 个月没有任何价值,因为没有售出单位。
我尝试使用 CInt 格式化字段,该字段在空单元格中放置了零,但它仍然只包含数字 > 的单元格。 0 作为分隔符...对于在所有 13 个月内都有销售的产品,平均值计算得很好。
我不知道如何告诉它计算总数并将其除以 13(月),即使特定月份没有值。
非常感谢任何帮助。
Group,
This is hard to explain, but I am building a matrix report in SSRS. My row includes a product code, my columns are months (previous 13) and my values are units sold for the corresponding product/month. I found some custome code that would let me change my subtotal to Avg However, for some products there might not be any units sold for a month so the cell is blank.
What is happening is say for product code X I sold 10 units in March 2009 and 1 unit in January 2010 for a total of 11. Instead of taking 11(units sold) / 13(months) it is taking 11 / 2 because it is only registering 2 months bbecause there aren't any values in the other 11 months because there were no units sold.
I tried formatting the field using CInt which placed zeros in the empty cells, but it still only includes cells that have a number > 0 as the divider... For products that have a sale in all 13 month the avg caluclates just fine.
I am not sure how I can tell it to take the total and divide it by 13(months) even if there are no values for a particular month.
Any help is greatly appreciate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的答案基于此自定义代码,用于获取平均值,如 Tom VdP 此处所述 。这得到了 SSRS 计算出的平均值。但是,您可以计算自己的“平均值”,因为
就您的目的而言,计数始终为 13。自定义代码方法会为您提供总和,因此您可以忽略使用 SSRS 来计算平均值,而只需替换平均值(Tom 的 avgValue)代码)与
I'm basing my answer on this custom code for getting the average as described by Tom VdP here. This gets the average as calculated by SSRS. However, you can calculate your own "average" because
For your purposes, the count is always 13. The custom code method gets you the sum, so you can ignore using SSRS to calculate the average and simply substitute the average (avgValue in the Tom's code) with