如何根据另一个字段的值从分组总和中排除一个值?
如何根据另一字段的值从分组总和中排除一个值?
即我打开报告=> Report Properties=>Code 并插入我的自定义代码,但是我如何更改以下代码以排除以下情况下另一个字段的数值?
Public Function ChangeWord(ByVal s As String) As String
Dim strBuilder As New System.Text.StringBuilder(s)
If s.Contains("Others") Then
strBuilder.Replace("Others", "Other NOT INCL")
Return strBuilder.ToString()
Else : Return s
End If
End Function
How do I exclude one value from a grouping sum, based on a value of another field?
ie I open Report=> Report Properties=>Code and insert my Custom Code, but how would I change the below code to exclude a numeric value of another field for the below case?
Public Function ChangeWord(ByVal s As String) As String
Dim strBuilder As New System.Text.StringBuilder(s)
If s.Contains("Others") Then
strBuilder.Replace("Others", "Other NOT INCL")
Return strBuilder.ToString()
Else : Return s
End If
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您想要从总和中排除数值,其中同一行上的单元格的字符串值包括“其他”,并且您提供的函数用作报表中表格的分组标准。 如果这不正确,我们深表歉意。
如果不使用第二段逻辑(函数或
Iif
条件),就不可能做到这一点。 我目前没有可用的 SSRS 来测试这一点,但是(假设您的值列是一个整数,代码将类似于:然后,在您希望出现条件总和的单元格中:
或者,您可以这样做 来实现此功能:
根据源数据的性质,您还可以通过将计算列添加到报表的源查询中来实现此目的。
通过在将出现条件总和的单元格中使用
Iif
支持第二个或第三个选项 - 自定义代码对于此目的似乎有点矫枉过正。I'm assuming you want to exclude a numeric value from a sum where the string value of a cell on the same row includes "Others", and that the function you've supplied is used as the grouping criteria for a table in the report. Apologies if this isn't correct.
It's not going to be possible to do this without using a second piece of logic, either a function or an
Iif
condition. I don't have SSRS available to test this at the moment, but (assuming your value column is an integer, the code will look something like:Then, in the cell where you want the conditional sum to appear:
Alternatively, you could do this without the function by using
Iif
in the cell where the conditional sum will appear:Depending on the nature of your source data, you could also do this by adding calculated columns to the report's source query.
I would favour the second or third option - custom code seems like overkill for this purpose.