Skip to main content

Notifications

Community site session details

Community site session details

Session Id : SLpGRgaqhs8N7Q1UGWfTjJ
Power Apps - Building Power Apps
Answered

Filtering by date and SQL in PowerApps

Like (0) ShareShare
ReportReport
Posted on 21 Jun 2022 09:08:26 by

Good day

I want to filter all the "closed" calls over the last 14 days from a SQL database in my PowerApps.

I have converted the date to int in SQL and have created a variable in the app as follows:

App / OnStart / Set(varDate, DateDiff(Today(),Days)-14)

(I have also used the following:  Set(varDate, DateDiff(ClsDateClosedTxt,Today(),Days)-14) without success)

The gallery's filter is as follows:

SortByColumns(Filter(vw_ITChangeRequests,Status="Closed" && varDate),"StatusDateInt", Descending).  

The filter produces all the results of all the closed calls and not just the last 14 days - can you please assist me 

Thank you

  • janineb Profile Picture
    on 23 Jun 2022 at 07:15:55
    Re: Filtering by date and SQL in PowerApps

    You are an absolute genius ... thank you Warren

  • Verified answer
    WarrenBelz Profile Picture
    146,645 Most Valuable Professional on 21 Jun 2022 at 21:07:40
    Re: Filtering by date and SQL in PowerApps

    Hi @janineb ,

    I have commented the code below - I cannot see your data, but this should help

    With(
     {
     wDate: //set wDate Variable to 14 days before today
     DateAdd( //done here for Delegation managment
     Today(),
     Days,
     -14
     )
     },
     SortByColumns(
     Filter(
     vw_ITChangeRequests, //Filter Table where
     Status = "Closed" && //Status is Closed AND 
     DateClosed < wDate //your closed date is more than 14 days ago (less then wDate)
     ),
     "StatusDateInt", //Sort by this field descending
     Descending
     )
    ) 

    If this is what you want, it should work.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

     

     

  • janineb Profile Picture
    on 21 Jun 2022 at 12:24:50
    Re: Filtering by date and SQL in PowerApps

    Thank you for your feedback.  I have tried your suggestion above, but unfortunately do not get any results (there should be at least 2 results).  The app does not show that there is an error.

  • janineb Profile Picture
    on 21 Jun 2022 at 12:23:27
    Re: Filtering by date and SQL in PowerApps

    Hi Warren

    I have commented out the "varDate" variable and copied your coding in the gallery.  It does not show an error in the app, but I still don't get any results.  There should be at least 2 results?

  • Mink21 Profile Picture
    158 on 21 Jun 2022 at 09:31:27
    Re: Filtering by date and SQL in PowerApps

    Hi @janineb 

     

    First of all, you should get the date by using DateAdd instead of DateDiff. Like this:
    Set(varDate,DateAdd(Today(),-14,Days))

    Once you have the date you can convert it to the same int format you have in SQL.

     

    Then, in your gallery I'd try the filter like this:
    SortByColumns(Filter(vw_ITChangeRequests, Status="Closed",  StatusDateInt >= varDate),"StatusDateInt", Descending)

     

    I hope this helps!

  • WarrenBelz Profile Picture
    146,645 Most Valuable Professional on 21 Jun 2022 at 09:26:49
    Re: Filtering by date and SQL in PowerApps

    Hi @janineb ,

    Two things - you need DateAdd to get the comparison date and you need to compare it with the Date Closed (I have assumed the field name below)

    With(
     {
     wDate: 
     DateAdd(
     Today(),
     Days,
     -14
     )
     },
     SortByColumns(
     Filter(
     vw_ITChangeRequests,
     Status = "Closed" && 
     DateClosed < wDate
     ),
     "StatusDateInt", 
     Descending
     )
    ) 

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,645 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,997 Most Valuable Professional

Leaderboard
Loading started