简体   繁体   English

在 SSRS 表达式中使用 like 运算符

[英]Using like operator in SSRS Expression

I have a tablix with following results.我有一个带有以下结果的 tablix。

SSRS Result SSRS 结果

Since i am learning SSRS.因为我正在学习 SSRS。 i wonder how to Sum line total with respect to product name.我想知道如何对产品名称求和。 Since product name has duplicate values but it has only M and Xl difference.由于产品名称有重复的值,但它只有 M 和 Xl 的区别。 If i use row group it won't total like i expected since it has M and Xl difference.如果我使用行组,它不会像我预期的那样总计,因为它有 M 和 Xl 差异。 I wonder how to write an expression for the total.我想知道如何为总数写一个表达式。 The desired result set期望的结果集

May 31 2011     S043659      Long-Sleeve Logo jerse M     3      $86.52
                             Long-Sleeve Logo jersey XL    1      $28.84
                                                           Total  $115.36
                             mountain bike socks M        6       $34.20

i used this expression but giving me an error.我使用了这个表达式,但给了我一个错误。

 `IIF((Fields!Product.value = Previous(Fields!Product.value),Sum(Fields!linetotal.value))`

There's actually a few things wrong with your expression.你的表达方式确实有一些问题。

The IIF doesn't have a 3rd argument for the ELSE value. IIF 没有 ELSE 值的第三个参数。 In this case, you'd want to use 0. So the expression would be IIF the fields match then LineTotal Else 0.在这种情况下,您希望使用 0。因此表达式将是 IIF 字段匹配然后 LineTotal Else 0。

You want to have the SUM on the outside of the IIF, otherwise it will only SUM one row.您希望 SUM 在 IIF 的外部,否则它只会 SUM 一行。

The matching without the size is trickier.没有尺寸的匹配更棘手。 I have it trim off the last 4 characters to exclude the size for a match - it may not work depending on your other Product names.我让它剪掉最后 4 个字符以排除匹配的大小 - 根据您的其他产品名称,它可能无法正常工作。

=SUM(IIF(LEFT(Fields!Product.value, LEN(Fields!Product.value) - 4) = LEFT(Previous(Fields!Product.value), LEN(Fields!Product.value) - 4), Fields!linetotal.value, 0))

The expression reads the SUM of (IF the Product matches the Previous Product then the Line Total else 0).该表达式读取总和(如果产品与上一个产品匹配,则行总计,否则为 0)。

All this being said, it would actually be easy to crate a parent group and GROUP BY on the parent product.话虽如此,实际上很容易在父产品上创建父组和 GROUP BY。 Unfortunately, your data uses a comma to separate one type (jersey) by size but a space in another (socks) so I don't see how to do it.不幸的是,您的数据使用逗号按大小分隔一种类型(运动衫),但在另一种(袜子)中使用空格,所以我不知道该怎么做。 If they all had a comma, I would create a Calculated Field on the dataset to use the product-line up to the comma.如果他们都有逗号,我会在数据集上创建一个计算字段,以使用逗号之前的产品线。

=LEFT(Fields!Product.value, INSTR(Fields!Product.value, ",") - 1)

IF your Product line is either a comma or space to separate, you might be able to use this for your Calculated Field:如果您的产品线是逗号或空格来分隔,您可以将其用于您的计算字段:

=LEFT(Fields!Product.value, 
    IIF(INSTR(Fields!Product.value, ",") > 0, 
        INSTR(Fields!Product.value, ",") - 1,
        InStrRev(Fields!Product.value, " ") - 1) )

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

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