web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Filtering on-prem SQL ...
Power Apps
Answered

Filtering on-prem SQL data source by date

(0) ShareShare
ReportReport
Posted on by 34

Consider the following table residing in an on-premise SQL database called DateTable (pulled into powerapps via an on-premise gateway):

 

Name   DateField

-------   ---------------------------

Item1    2015-01-01 00:00:00

Item2    2017-01-01 00:00:00

 

When I try to filter this table in Powerapps using the following statement, nothing comes back.

Filter('[dbo].[DateTable]', DateField > DateValue("1/1/2016"))

 

To debug the issue, I created the following collection:

ClearCollect(DateCollection, {Name: "Item1", DateField: DateValue("1/1/2015")}, {Name: "Item2", DateField: DateValue("1/1/2017")})

 

The same filter expression applied to this collection works and correctly brings back the one row for 2017:

Filter(DateCollection, DateField > DateValue("1/1/2016"))

 

Any idea why I can't filter my SQL data source by date?

 

Thanks!

Categories:
  • rgruian Profile Picture
    Microsoft Employee on at

    The type of your DateField column in SQL is unclear. You are listing the values as 2105-01-01 00:00:00 and such, but are those text values or actual date/time values?

     

    If the former, could you please try this instead:

    Filter('[dbo].[DateTable]', DateValue(DateField) > DateValue("1/1/2016"))

     

  • df Profile Picture
    34 on at

    Hi Radu,

     

    Thanks for your response. Here is the table definition:

     

    CREATE TABLE dbo.DateTable (Name varchar(10) PRIMARY KEY, DateField DATETIME)
    INSERT INTO dbo.DateTable VALUES ( 'Item1', '2015-01-01')
    INSERT INTO dbo.DateTable VALUES ( 'Item2', '2017-01-01')

     

    As you see, the column is defined as DATETIME. So when I use the formula you suggested I get this error:

    "Invalid argument type (DateTime). Expecting a Text value instead."

     

     

  • Verified answer
    rgruian Profile Picture
    Microsoft Employee on at

    This is a bug in PowerApps, which I have just filed and dispatched to the correct area owners. We will address this as soon as possible. In the mean time, if you are blocked, please use one of the following workarounds:

     

    1. If possible, use a DATETIMEOFFSET type for your field instead of DATETIME.

    2. Force-inhibit the delegation of the query to the SQL back end, by using non-delegatable constructs. For example:

         Filter('[dbo].[DateTable]', Day(DateField) > 0 && DateField > DateValue("1/1/2016"))

     

    Keep in mind that #2 will run the query locally on up to 500 rows, though. If your data is larger than 500 rows, you will need to go the route of #1 for now until this problem is fixed.

     

    I hope this helps.

     

  • df Profile Picture
    34 on at

    Great, thank you. The dataset is large, so local processing is not an option. Will you post an update here once the bug has been fixed?

     

    Thanks!

  • rgruian Profile Picture
    Microsoft Employee on at

    Will do. Thanks for your patience!

  • francorg Profile Picture
    15 on at

    Is there a way to filter using a "Today" or "Now" variable in a Flow connecting to SQL Server on-prem?

    Like "Orderdate ge Today()"

    And what about a way to have it filter only dates greater than the last execution time of the Flow?

     

    Thank you,

    Roberto

  • LateNightDBA Profile Picture
    13 on at

    Another solution is to add your hours offset to the datetime values before being stored/used for query/filter. This will then equate back to the original date value only.

    Example in Hong Kong (GMT+8) I add 8 hours to the datevalue.

    Hope that also helps.

     

    Looking forward to the update....

     

     

  • ericrick Profile Picture
    6 on at

    Is there an update on this getting fixed?   Facing the same situation and it's been a year since mentioned.

  • claydevin Profile Picture
    4 on at

    Is there any update on this issue?   We tried the DateTimeOffSet suggestion, but could not get that to work.   We also tried turning the datetime into a number and evaluating that way, but that also is proving challenging.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Has this been fixed yet?  I mean seriously? Cant filter a SQL data source using datetime inequalities?  And this was over a year ago..

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 243 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 190 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard