如何根据另一个字段的值从分组总和中排除一个值?

发布于 2024-07-16 22:31:57 字数 421 浏览 5 评论 0原文

如何根据另一字段的值从分组总和中排除一个值?

即我打开报告=> 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 技术交流群。

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

发布评论

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

评论(1

太阳哥哥 2024-07-23 22:31:57

我假设您想要从总和中排除数值,其中同一行上的单元格的字符串值包括“其他”,并且您提供的函数用作报表中表格的分组标准。 如果这不正确,我们深表歉意。

如果不使用第二段逻辑(函数或 Iif 条件),就不可能做到这一点。 我目前没有可用的 SSRS 来测试这一点,但是(假设您的值列是一个整数,代码将类似于:

Public Function ExcludeOthers(rowDesc As String, rowVal as integer)
    if ChangeWord(rowDesc) = "Other NOT INCL"
        Return 0
    else
        Return rowVal
    end if
End Function

然后,在您希望出现条件总和的单元格中:

=Sum(ExcludeOthers(Fields!desc.Value,Fields!val.Value))

或者,您可以这样做 来实现此功能:

=Sum(Iif(ChangeWord(Fields!desc.Value) = "Other NOT INCL",0,Fields!desc.Value))

根据源数据的性质,您还可以通过将计算列添加到报表的源查询中来实现此目的。

通过在将出现条件总和的单元格中使用 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:

Public Function ExcludeOthers(rowDesc As String, rowVal as integer)
    if ChangeWord(rowDesc) = "Other NOT INCL"
        Return 0
    else
        Return rowVal
    end if
End Function

Then, in the cell where you want the conditional sum to appear:

=Sum(ExcludeOthers(Fields!desc.Value,Fields!val.Value))

Alternatively, you could do this without the function by using Iif in the cell where the conditional sum will appear:

=Sum(Iif(ChangeWord(Fields!desc.Value) = "Other NOT INCL",0,Fields!desc.Value))

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.

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