简体   繁体   English

数字之间的SSRS表达式总和

[英]SSRS Expression Sum Between Numbers

I am seeking assistance with creating a VB expression in SSRS that subtracts SUMS. 我正在寻求在SSRS中创建VB表达式(减去SUMS)的帮助。 I have a dataset that has accounts and corresponding money/amount values. 我有一个具有帐户和相应金额的货币数据集。 I need help creating an expression that sums up the money/amount values from one group of the accounts in a specified range, and then subtracts it from the money/amount total of another range. 我需要帮助来创建一个表达式,该表达式将指定范围内一组帐户的货币/金额值相加,然后从另一范围的货币/金额总计中减去。 Specifically: 特别:

(Sum(amt) where acct between 40000 and 49999) -
(Sum(amt) where (acct between 50000 and 59999) or (acct between 66000 and 69999)) -
(Sum(amt) where acct between 76000 and 79825) -
(Sum(amt) where acct between 89000 and 90399)

Really need help translating this SQL logic into a VB expression to be used for a textbox in SSRS. 确实需要帮助将此SQL逻辑转换为VB表达式以用于SSRS中的文本框。 Any advice would be extremely helpful! 任何建议都将非常有帮助! Thanks! 谢谢!

textbox can only capture the first value of the dataset, so if you go to the expression builder for the textbox, you can see there are no fields from the dataset available. 文本框只能捕获数据集的第一个值,因此,如果转到文本框的表达式构建器,则可以看到数据集中没有可用的字段。 But, aggregate functions on dataset fields are available. 但是,可以使用数据集字段上的聚合函数。

So you can create a calculated field to your dataset and add amount values to it with appropriate signs such that the sum of all the values in this calculated field represents your desired solution. 因此,您可以为数据集创建一个计算字段,并使用适当的符号向其添加数量值,以使此计算字段中所有值的总和代表您所需的解决方案。

For example, add a new calculated field to your dataset. 例如,向您的数据集添加一个新的计算字段。 In the field source, add an appropriate expression like: 在字段源中,添加一个合适的表达式,例如:

=IIF(Fields!acct.Value>=40000 AND Fields!acct.Value<=49999, CInt(Fields!amt.Value),
   IIF(   (Fields!acct.Value>=50000 AND Fields!acct.Value<=59999)  OR
          (Fields!acct.Value>=66000 AND Fields!acct.Value<=69999)  OR
          (Fields!acct.Value>=76000 AND Fields!acct.Value<=79825)  OR
          (Fields!acct.Value>=89000 AND Fields!acct.Value<=90399), 
                 CInt(0 - Fields!amt.Value), CInt(0)
      )
    )

This keeps the values between 40000 and 49999 as they are. 这样会将值保持在40000和49999之间。 Makes all values needed to be subtracted into negative values. 使所有需要减去的值变为负值。 And everything else you don't wish to consider as 0. 其他所有您不希望视为0的值。

Therefore when you call 因此,当您致电

Sum(Fields!calcfield.Value, "your dataset name")

from the textbox, you add the values between 40000 and 49999, and subtract values in ranges you wanted. 从文本框中,添加40000到49999之间的值,并减去所需范围内的值。

Please change the expression for the calculated field as per your need, the procedure will work. 请根据需要更改计算字段的表达式,此过程将起作用。 You shouldn't go through all the values in a dataset directly from a textbox. 您不应该直接从文本框中浏览数据集中的所有值。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM