I have 2 parameters in my query @selectedMonth and @selectedYear. I have 5 different date columns and I need to count all rows for each column where the month and year in the date match the parameters selected.
I have set up each parameter with a set of available values (month names Jan to Dec with values 1 to 12 respectively) and (Years 2018 to 2022 inclusive and the values are the same as the label).
In my SQL query I have used the following in the WHERE clause:
(updated 4/2/19 to show whole where clause)
(DATEPART(mm, createdon) = @selectedMonth) AND (DATEPART(YY, createdon) = @selectedYear) OR (DATEPART(mm, sb_provisionalstatuschangedate) = @selectedMonth) AND (DATEPART(YY, sb_provisionalstatuschangedate) = @selectedYear) OR (DATEPART(MM, sb_confirmedstatuschangedate) = @selectedMonth) AND (DATEPART(YY, sb_confirmedstatuschangedate) = @selectedYear) OR
(sb_status = 3) AND (statecode = 1) AND (DATEPART(MM, sb_eventdate) = @selectedMonth) AND (DATEPART(MM, sb_eventdate) = @selectedYear) OR (statecode = 2) AND (DATEPART(MM, actualclosedate) = @selectedMonth) AND (DATEPART(YY, actualclosedate) = @selectedYear)
and I have used the following Expression in SSRS table (in the first column - I will need similar in the other 4 date columns):
=SUM(iiF(Fields!createdon.Value=Parameters!selectedMonth.Value AND Fields!createdon.Value=Parameters!selectedYear.Value),1,0)
I think I need the expression because the WHERE is using OR's across the 5 date columns and I only want it to count the valid dates in each column.
I am not quite sure where the problem lies. I thought that I might need to specify the 'Month' part of Fields!createdon.value is equal to the parameter value? (and same for year), however I cannot work out how to do that in an expression. Or maybe the syntax is completely wrong.
Sorry but I have looked at this so long I cant see the woods for the trees. If someone could point me in the right direction I am happy to carry on researching how to do it but need a nudge please.