Selecting data of previous month and year

Hi,
I want to ask about Recordset_Selecting,
my code below works fine,

function Recordset_Selecting(&$filter)
{
 if (CurrentPageID() == "list" || CurrentPageID() == "view")
 AddFilter($filter, "MONTH(DATE_DEAL) = MONTH(CurDate()) AND YEAR(DATE_DEAL) = YEAR(CurDate())");
}

The process above performs the task of filtering the current month and year when the listpage is loaded.
My question is how do I want to filter the previous month and year, I have tried using “Query Builder” but it doesn’t work. I want this filter to be flexible.
Sometimes users want to see data for the last month and year,
Thank You

If you meant you want to change search criteria, you need to execute another SQL by submitting to the page again with another search criteria. If you are using summary report, you may add your own filters, see Page_FilterLoad server event.

For example, I have 3 options (pending, completed, cancel) in the sales data,
on the listpage I did record_selecting = “pending”.
How can users flexibly see completed and canceled data but when loading the listpage the data presented is “pending”?
Did I put the wrong code in record_selecting?
basically when the first listpage loads record_selecting = “pending” but the user can also see the listpage completed and canceled?

For such case, then you should not use Recordset_Selecting server event, because once you filter the recordset using this event, then you cannot display another records that hidden from that filter.You better enable Ext. Search option under Fields setup → List Page for the that field that contains those 3 options (pending, completed, cancel).

Let’s say the field name is the_option, after that, you may adjust the URL to the page become like this:yourlistpage?cmd=searchz_the_option=%3D&x_the_option=pending&search=&searchtype=Adjust yourlistpage and the field name to your needs.That will display the records that contains “pending” for the_option field, so that you may reset the search to display another records.

I’ve tried activating Ext. Search, ext results. search displayed in the column:
pending
pending
completed
completed
cancel
cancel.can it be differentiated into:
pending
completed
cancel.Where do you put the URL you suggest?
“yourlistpage?cmd=searchz_the_option=%3D&x_the_option=pending&search=&searchtype=”

You may use MenuItem_Adding server event in order to change the URL of the related menu item that will point to that List Page.