Question

I am trying to build a report in Report Builder 3.0 which will populate the column headers every business week starting Monday with the dates of each day in that week. The report will then do a count of each time those dates appear in a "Dates Received" field for a given row entry (see Figure 1 below).

I am wondering how to create a filter or parameter in Report Builder to only show the dates of the current week given even if the report runs daily, and then still be able to do a count.

Figure 1: Matrix Mock-up (Dates are of Current Week) enter image description here

Previously I was using this code to get columns in a table to show the next five business days (which doesn't work here because I need the business days for just that week):

=IIF(6 - WeekDay(Today()) - X < 0, DateAdd("d", X + 2, Today()), 
DateAdd("d", X, Today()))
Was it helpful?

Solution

The easiest thing to do is to get SQL to do the heavy lifting for you and prepare the data in a way that is most convenient for reporting. So what we want to do is get all the data that relates to the current week's business days - that is, anything from the Monday of this week to the Friday of this week:

SELECT PersonId, SomeDate
FROM MyTable
WHERE SomeDate >= DateAdd('d', 0 - (WeekDay(Today())-2), Today())  // Monday
AND SomeDate <=  DateAdd('d', 0 - (WeekDay(Today())-6), Today())  // Friday

Then you just feed this into your matrix, grouping on the person and the date and you're good to go.

OTHER TIPS

I haven't got the tool avaliable but if you add a filter to the dataset or table to essentually:

X > today() - day of the week --this will get the date for the sunday

And

X < today() + (6 - day of the week) --this will get the date for saturaday

This will ensure your data is between monday and friday.

Declare @DateFrm datetime= N'2014-11-04' 
Select 
    [EnquiryTypeValue],
    [CallerValue],
    Created  
FROM [BPU].[dbo].[vwEnquiry]  
WHERE 
    CAST(Created as date) between DATEADD(ww, DATEDIFF(ww,0,@DateFrm), 0) 
        and DATEADD(ww, DATEDIFF(ww,0,@DateFrm), 6)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top