Question : Conditional Row Filtering based on column grouping

Hi
I am creating a report in SQL Server reporting services 2005.
My report is reporting on 2 parameters: Quantity sold, Cost Price. This data is fetched for top 30 items sold (sum of Cost price in descending order). Now the data is fetched for a whole calendar month. Then for these 30 items, the report needs to show historic data for calendar month immediately preceding this reported month. Also report needs to show historic data for same month last year.
e.g. For Oct-09 , items A-z were sold (sum of cost price desc order). Now my report will show for these 30 items, the quantity sold and the sum of cost of these items (grouped by item name) for Oct-09, Sep-09 and Oct-08.

Now i have used a matrix control with following specs-
with row grouping = item name....filter = sum(cost price) top30.... sorting = sum(cost price) desc

column grouping1 = year(solddate) ....Filter = 2008 and 2009
column grouping2 = month(solddate) ...Filter = Oct and Sep
column grouping3 (static) = quantity sold and cost price
 
The problem i am having is the report is selecting all items in the table and not just the top 30 (based on sum of cost price in Oct09).

Answer : Conditional Row Filtering based on column grouping

Hi
I developed the solution. Firstly I used the table control instead of a matrix control. Then for my input parameter, I let the user select a month and year (and no start/emd dates) and passed a whole month to the dataset. This made  my select statement a lot simple.
Then I used CASE statement to get data for the 3 date ranges (e.g. if user selected Oct09, then I fetched 'Cost' and Quantity Sold' for Oct 09, Sep 09 and Oct 08) in 6 different columns (see code below). The FROM and WHERE statements are normal statements as required.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
SELECT     
SUM(CASE WHEN month(soldDate) = @month AND year(soldDate) = @year THEN CostPrice ELSE 0 END) AS CostCurrentMonth, 
SUM(CASE WHEN month(soldDate) = @month AND year(soldDate) = @year THEN SoldQuantity ELSE 0 END) AS QtyCurrentMonth, 
SUM(CASE WHEN @month = 1 AND month(soldDate) = 12 AND
year(soldDate) = @year THEN CostPrice ELSE CASE WHEN month(soldDate) = @month - 1 AND year(soldDate) = @year THEN CostPrice ELSE 0 END END) AS CostLastMonth,
SUM(CASE WHEN @month = 1 AND month(soldDate) = 12 AND
year(soldDate) = @year THEN SoldQuantity ELSE CASE WHEN month(soldDate) = @month - 1 AND year(soldDate) = @year THEN SoldQuantity ELSE 0 END END) AS QtyLastMonth,
SUM(CASE WHEN month(soldDate) = @month AND year(soldDate) = @year - 1 THEN CostPrice ELSE 0 END) AS CostSameMonthLastYear,
SUM(CASE WHEN month(soldDate) = @month AND year(soldDate) = @year - 1 THEN SoldQuantity ELSE 0 END) AS QtySameMonthLastYear
FROM table1......
Random Solutions  
 
programming4us programming4us