Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

Evaluate to see if two date fields are in range of any existing records in the common data service

Hi PowerApps community,


I'm struggling on a requirement for an App I'm busy building to do the following:


  • Before submitting a patch (create record), I need to determine if the dates selected already exist in the Common Data Service (CDS), if they do, prevent use of the button, otherwise allow the button to be selected (editable).
  • Two date fields exist from a CDS new form, StartDate and EndDate (Renamed the date picker to these names respectively)
  • CDS field is called DateFrom and DateTo respectively



Setting displaymode on my button, I need to determine if the dates selected (StartDate and EndDate) fall on or between any of the other dates in the CDS with regards to DateFrom and DateTo.

I.e. if I select StartDate --> 17/10/2019 and EndDate --> 18/10/2019, check to see if there are any other records in the CDS entity that fall on or between that date. If it does, set displaymode to disabled, otherwise set displaymode to edit.




Does anyone have any sort of formula that would help in this regard?



Barry Francis


Hi Kris Dai,


Just to confirm, there are four end dates in the last two OR statements, is that correct? Or should there be a start date somewhere inbetween?




If the above is correct, its still allowing for time periods to cross over those time periods:


Third Attempt.jpg


As you can see from the above, I should not be able to enable the button when the start and end dates cross over existing record data within that time period.



Barry Francis


Hi there,


I am trying a few things to resolve this, one of the solutions I'm looking at is to create a collection of dates inbetween the two selected dates, then use a lookup to see if there is a match across the one gallery to the other.


Here is the collection I am setting on change of the two date pickers:


DateDiff(StartDate.SelectedDate, EndDate.SelectedDate, Days) + 1),
"Day " & (Value + 1),
DateAdd(StartDate.SelectedDate, Value, Days)


Then I am setting the values into a gallery:


Alternate Solution.jpg


Then I am setting a label to try and work in a lookup to see if any of records on the individual date gallery matches one of the dates in the other gallery, but am struggling to get that IF formula correct:


If(!IsBlank(LookUp(SingleDateGallery.AllItems, Value(Text(Date, "[$-en-US]yyyymmdd")) = Value(Text(DateFromGallery, "[$-en-US]yyyymmdd")))),"Date Found","No Dates Found")


SingleDateGallery --> gallery with each date listed out

Date --> The date each collect is returning

DateFromGallery --> The date labels in the gallery with the from and to dates.



Barry Francis


Hi Kris Dai,


I played around with the code you sent me and found the solution:


!IsBlank(LookUp('Leave Requests', Value(Text(crbb9_datefrom, "[$-en-US]yyyymmdd")) <= Value(Text(StartDate.SelectedDate,"[$-en-US]yyyymmdd")) && Value(Text(crbb9_dateto, "[$-en-US]yyyymmdd")) >=
Value(Text(StartDate.SelectedDate, "[$-en-US]yyyymmdd")))) ||
!IsBlank(LookUp('Leave Requests', Value(Text(crbb9_datefrom, "[$-en-US]yyyymmdd")) <= Value(Text(EndDate.SelectedDate,"[$-en-US]yyyymmdd")) && Value(Text(crbb9_dateto, "[$-en-US]yyyymmdd")) >=
Value(Text(EndDate.SelectedDate, "[$-en-US]yyyymmdd")))) ||
!IsBlank(LookUp('Leave Requests', Value(Text(crbb9_datefrom, "[$-en-US]yyyymmdd")) > Value(Text(StartDate.SelectedDate, "[$-en-US]yyyymmdd")) && Value(Text(crbb9_dateto, "[$-en-US]yyyymmdd")) <
Value(Text(EndDate.SelectedDate, "[$-en-US]yyyymmdd")))),


The start date must be less than the from date and the end date must be greater than the to date.


Thanks for all the assistance.



Barry Francis

Helpful resources

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.


Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (8,323)