Filtering dataset


08-11-2010, 2:19 AM
I want to filter my dataset on a datetime field, but I seem to be unable to do that. I can filter using an expression with 'Hour', but I can't seem to find a way to filter the set where it is filtered with a time value of HH:mm or H:mm. What expression should I use to achieve this?

Re: Filtering dataset


08-13-2010, 2:04 AM
Hello,
You may want to use 2 filters, one of them for hour value, another one for minute value, like:
1st filter : Fields!dt.Value.Hour = 1
2nd filter: Fields!dt.Value.Minute = 15

Sergey Abakumoff
GrapeCity

Re: Filtering dataset


08-13-2010, 3:27 AM
I tried that approach as well and it works fine when you are looking for a filter that only filters for values that are equal, but I found that it did not result in the filter that I wanted.
For example: if I want to see the results that are bigger than 1:15 then I would make 2 expressions:
1st filter : Fields!dt.Value.Hour > 1
2nd filter: Fields!dt.Value.Minute > 15

The problem with this is that I would not get 2:14 returned as the minute part is not bigger than 15.

Re: Filtering dataset


08-13-2010, 5:48 AM
Ok, then we can use the TimeOfDay property of System.DateTime structure to build the filter.
I found that it quite hard to describe the approach so that it would be clear, so I attach the example.
Take a look at the code of the report, it contains the function that returns the time of day for the date, hour and minute that are passed as arguments.
In the filter value I call that function for the current field value and hour, minute which I want to use for the filter.
Filter expression : =Fields!StartTime.Value.TimeOfDay
Filter operator : greater
Filter value : = Code.GetFilterValue(Fields!StartTime.Value, 1, 15)

So the result will contain the records with time of day greater then time of day of the same date, but 1:15 AM.

Does that make sense and help?



Sergey Abakumoff
GrapeCity

Re: Filtering dataset


08-13-2010, 6:06 AM
I do understand what you are doing here and it is a nice solution, but in the end it would not be workable for me I think.

The filter I want needs to give my users insights in the results that are made within a certain timeframe. For example: how many sales did we have from 13:48 till 15:33 in this year? That way they can get insights in what time of day is most busy and might plan on how many people should work at any given time.

For now I have settled with the Hour filter and they can only see information on whole hour (14:00 till 16:00).

Re: Filtering dataset


08-13-2010, 6:24 AM
Could you explain why the scenario you mentioned(sale time between 13:48 and 15:33) would not be achieved by using two filters that make use of the technique I described:
(1)
Filter expression : =Fields!SaleDate.Value.TimeOfDay
Filter operator : greater
Filter value : = Code.GetFilterValue(Fields!
SaleDate.Value, 13, 48)

(2)
Filter expression : =Fields!
SaleDate.Value.TimeOfDay
Filter operator : less
Filter value : = Code.GetFilterValue(Fields!
SaleDate.Value, 15, 33)

The values 13,48,15,33 may be replaced with the report parameters values that are entered by end-users.

Sergey Abakumoff
GrapeCity

Re: Filtering dataset


08-13-2010, 6:59 AM
I understood the sample incorrectly first, but now I see that it would indeed provide the solution that I need.
However, there is still a problem that I don't think can be solved. The problem for me with this solution is that the function is saved in the code portion of the report. I have build a custom viewer that allows my users to create their own filters in a simple way. Since they can make their own reports as well I can never be sure if the code you provided is included in their reports.