简体   繁体   中英

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. Here's a small example of the database table that I'm querying to produce the SSRS report.

|---------------------|------------------|------------------|
|      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. 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))

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. The result is that in column # Sales Wk 20, it shows a 5 for Alpha, a 1 for Beta, and a 2 for Coolbeans.

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. I did, however, use a row group for the companies.

Your expression should use SUM instead of 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.

Try just adding =CountRows() as part of your formula, and ssrs handles the grouping for you. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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