Hamza Zaidi
Hamza Zaidi

Reputation: 401

RDLC Report: Apply Filter to Report

I have two parameters dateFrom and dateTo which I want to filter my report based on those values and show sum of total column of filtered rows in the report.

Currently when I use expression =Sum([total]) it returns the sum of whole column in database and it doesn't applying date filter on expression.

Question: How to apply sum of total between dates dateFrom and dateTo parameter like Something like this pseudo-code:

=Sum(Field!Total.Value) where date between dt_from to dt_to

Here is the code I use to load show report:

invoice_viewTableAdapter.Fill(this.db_posDataSetInvoice.invoice_view);
reportViewer1.RefreshReport();

Upvotes: 2

Views: 4395

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125197

You should apply the filter on the data source of your report, for example:

invoice_viewTableAdapter.Fill(this.db_posDataSetInvoice.invoice_view);
this.invoice_viewBindingSource.Filter = "Put your filter here";
reportViewer1.RefreshReport();

Supposing you have a MyDateField field and you have dateFrom and dateTo of type of DateTime.

This can be your date filter:

String.Format("MyDateField>= #{0:yyyy/MM/dd}# AND MyDateField<= #{1:yyyy/MM/dd}#"
              , dateFrom, dateTo);

you can find more information about about BindingSource.Filter expression syntax here.

Upvotes: 2

Related Questions