简体   繁体   English

SSRS“ where子句”

[英]SSRS 'where clause'

I've got a table that contains sales information for several companies. 我有一个表,其中包含一些公司的销售信息。 Each sales transaction the company makes is stored in the table, and the week of the year (1-52) that the sale took place within is stored also. 公司进行的每个销售交易都存储在表中,还存储了进行销售的一年中的一周(1-52)。 Here's a small example of the database table that I'm querying to produce the SSRS report. 这是我正在查询以生成SSRS报告的数据库表的一个小示例。

|---------------------|------------------|------------------|
|      Company        |         Week     |Sales_Transaction |
|---------------------|------------------|------------------|
|        Alpha        |         20       |      1.00        |
|---------------------|------------------|------------------|
|        Alpha        |         20       |      2.00        |
|---------------------|------------------|------------------|
|        Beta         |         20       |      9.00        |
|---------------------|------------------|------------------|
|        Alpha        |         21       |      5.00        |
|---------------------|------------------|------------------|
|        Coolbeans    |         21       |      5.50        |
|---------------------|------------------|------------------|
|        Alpha        |         22       |      2.00        |
|---------------------|------------------|------------------|
|        Alpha        |         22       |      2.00        |
|---------------------|------------------|------------------|
|        Coolbeans    |         22       |      3.00        |
|---------------------|------------------|------------------|

I have a matrix with a row group which produces a line in the matrix for each company. 我有一个带有行组的矩阵,该矩阵在每个公司的矩阵中产生一条线。 The matrix has 52 additional columns for each week of the year. 矩阵中一年中的每个星期都有52个其他列。 Here's a condensed version of the matrix and data I want to see. 这是我要查看的矩阵和数据的精简版本。

|--------------|---------------|----------------|----------------|
|   Company    | # Sales Wk 20 |  # Sales Wk 21 |  # Sales Wk 22 |
|--------------|---------------|----------------|----------------|
|   Alpha      |       2       |      1         |      2         |
|--------------|---------------|----------------|----------------|
|   Beta       |       1       |      0         |      0         |
|--------------|---------------|----------------|----------------|
|   Coolbeans  |       0       |      1         |      1         |
|--------------|---------------|----------------|----------------|

To count the number of sales transactions for each week for each company, I'm using this expression like this for each column: 为了计算每个公司每周的销售交易数,我在每个列中使用以下表达式:

=Count(IIF(Fields!Sales_Week_Number.Value = "20", Fields!Sales.Value, 0)) = Count(IIF(Fields!Sales_Week_Number.Value =“ 20”,Fields!Sales.Value,0))

Using the example expression above which I'm placing in the # Sales Wk 20 matrix column, the problem is that instead of counting ONLY the transactions that occurred in week 20, it counts transactions for all weeks for the company. 使用上面放置在#Sales Wk 20矩阵列中的示例表达式,问题在于,它不只计算第20周发生的交易,而是计算公司所有周的交易。 The result is that in column # Sales Wk 20, it shows a 5 for Alpha, a 1 for Beta, and a 2 for Coolbeans. 结果是,在#Sales Wk 20列中,Alpha显示5,Beta显示1,Coolbeans显示2。

What do I need to do to make it only count the sales transaction from the specific week? 我需要怎么做才能使其仅计算特定星期的销售交易?

Side Note: Regarding the 52 columns for each week of the year, I intentionally did not use a column group for this b/c I need to do some other calculations/comparisons with another matrix which doesn't play nice when column groups are used. 旁注:关于一年中每周的52列,我故意没有为此b / c使用列组,我需要对另一个矩阵进行其他计算/比较,这在使用列组时效果不佳。 I did, however, use a row group for the companies. 但是,我确实为公司使用了行组。

Your expression should use SUM instead of count 您的表达式应使用SUM而不是count

=SUM(IIF(Fields!Sales_Transaction.Value=0,0,1))

在此处输入图片说明

在此处输入图片说明

I think you may be going down the wrong path here. 我认为您可能在这里走错了路。 Since your using a matrix in SSRS, then the easiest way is to make SSRS handle the separation for you rather than building a WHERE. 由于您在SSRS中使用矩阵,因此最简单的方法是让SSRS为您处理分离,而不是构建WHERE。

Try just adding =CountRows() as part of your formula, and ssrs handles the grouping for you. 尝试仅将=CountRows()作为公式的一部分添加,然后ssrs为您处理分组。 I'll check the format of the command when I'm on-line properly not on my phone. 当我正确在线时(不在手机上),我将检查命令的格式。

在矩阵的值列中使用此表达式-

=IIf((Fields!Sales_Transaction.Value)>0,Count(Fields!Sales_Transaction.Value),0);

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

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