Today I faced an issue to get the records in PowerApps from SQL database by applying date filters (From and To Dates). I spent so much time to retrieve the records by using the below command “ClearCollect(FilteredWorkReports,Filter(‘[SQL_Table_Name]’, ReportDate >= FromDate.SelectedDate && ReportDate <= ToDate.SelectedDate))“, but I didn’t get the expected result. The reason is simple “Direct date filters do not work for SQL Server” based on this link from MS. So, the solution for this issue is to create a calculated column for the date column in SQL table with Integer datatype. The formula for this calculated column is “YEAR([your_date_field]) * 10000 + MONTH([ your_date_field ]) * 100 + DAY([ your_date_field ])“. The data in your table will look like below with new field
Customer | ReportDate | ReportDateAsInt |
Cust 1 | 2019-05-01 | 20190501 |
Cust 2 | 2018-11-08 | 20181108 |
Cust 3 | 2015-12-15 | 20151215 |
Cust 4 | 2018-06-07 | 20180607 |
Finally, I applied the date filter with new column like below which is working like a charm 🙂 “ClearCollect(FilteredWorkReports,Filter(‘[SQL_Table_Name]’,ReportDateAsInt >= Value(Text(FromDate.SelectedDate,”[$-en-US]yyyymmdd”)) && ReportDateAsInt <= Value(Text(ToDate.SelectedDate,”[$-en-US]yyyymmdd”))))“.
I hope it helps…..