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 / ClearCollect(Filter(SQ...
Power Apps
Unanswered

ClearCollect(Filter(SQLDataSource,DateTime>DateTimeValue(DatePicker.SelectedDate))) Doesn't Work

(1) ShareShare
ReportReport
Posted on by 64

Hello, the following code returns an error:


ClearCollect(punchReport,Filter('[dbo].[Punch]',InTime>DateTimeValue("2020-01-01 00:00:00.001")));

 

Annotation 2020-02-18 093117.png

 

The SQL data line from SSMS is below:

 
 

SQL Server - Line I'm trying to collectSQL Server - Line I'm trying to collect

 

I've tried different ways to represent the date in the formula. Not a single method works. The following thread represents the same issue from 2016 with multiple people in months following having the same issue:

https://powerusers.microsoft.com/t5/Building-Power-Apps/Filtering-on-prem-SQL-data-source-by-date/td-p/6151

 

Why doesn't this work?

Categories:
I have the same question (0)
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Is it possible that you're using the punchReport somewhere else in your app with a different data scheme?

  • ocdc2008 Profile Picture
    64 on at

    @Anonymous 

     

    No, this is entirely isolated to a testing screen.

     

    Based on what I'm finding elsewhere in the community, PowerApps doesn't support the ability to use the < and > operators when using ClearCollect(Filter()) in reference datetime fields in a SQL server. The issue existed in 2016 from previous posts and there have been many comments since then up through mid 2019 that indicate the issue hasn't been addressed.

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Ah, I see. I did a test on my end and I got the same result. Here's how I got around it.

    ClearCollect(testCol,'[dbo].[SqlTable]');
    ClearCollect(testCol,Filter(testCol,DateTimeColumn<Now()))

    Collect the table, then filter it.

    ---
    If this answered your question, please click "Accept Solution". If this helped, please Thumbs Up.

  • ocdc2008 Profile Picture
    64 on at

    @Anonymous 

     

    Unfortunately that isn't going to work. I need these instructions to be delegable. I'll be filtering through thousands of records over time.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Keep in mind your rows may get cut off depending on the size of your table and your row limit. You can sort the sql table if you need the newest records, since you're dealing with datetime.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    My recommendation then, would be to use a SQL view or a stored procedure and get results via Power Automate. Would that be an option for you?

  • ocdc2008 Profile Picture
    64 on at

    @Anonymous 

     

    Yes that would be an option.

     

    I'm already using Automate to get around the fact that the "In" operator isn't delegable. I'd like to avoid having to use so many interfaces. I may just add a field to the SQL table that is in date format and filter using the = operator.

     

    Not the most elegant solution, but it'll work.

  • Daryl LaBar Profile Picture
    156 Most Valuable Professional on at

    Converting the DateTime Column in your SQL DB to DateTimeOffset resolves this issue.  I've detailed a blog post here on how to do so.

  • tpampalone Profile Picture
    13 on at

    @Dlabar , appreciate your documentation. I solved this issue a while back by converting my date field (rescheduleDate) in an Azure SQL DB to datetimeoffset(0). This allowed me to run filter ranges by the week using a

    ClearCollect function such as:
    ClearCollect(colWeeklyEvents, Filter(coatingPlanner ,rescheduleDate > varFirstWeek And rescheduleDate <= DateAdd(varFirstWeek, 7, TimeUnit.Days)));

    I have run into this issue again however, where the code just stopped working. Was wondering if you had any follow up to your blog post to see if this has been a recurring issue for users. The collection I have populates a calendar gallery and am getting "Error when trying to retrieve data from the network". No code has changed in the past 1.5 years of initially resolving this issue. 
    Help appreciated.

  • Daryl LaBar Profile Picture
    156 Most Valuable Professional on at

    Unfortunately, this sounds like something that will need a MS support ticket created for it.  If you haven't changed anything, it sounds still work.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 94

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard