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 / prevent users from cre...
Power Apps
Answered

prevent users from creating new item if date ranges in form cross over with items in datasource

(0) ShareShare
ReportReport
Posted on by 8

I'm currently developing an app for collecting Conflict of Interest Declarations.


Every year there is an annual cycle in which every employee must submit a new declaration. I've created a feature for HR to set an Annual cycle with Start date, End date, and Cycle name. This data is stored in a separate list from the declarations.

 

There should only ever be one Cycle that can be live over any given period, and they should never cross over. Currently I have some visual cues to indicate if cycle is live based on today's date is on or between the Start and End dates. However, I would like to prevent HR from accidentally creating cycles with date crossover by disabling the save button if there is crossover with an already saved Cycle.

I'm not entirely sure how to achieve this though. I thought about using the Sequence function to list all dates between start and end dates (inclusive) of each cycle already created, and comparing with a Sequence of dates between the start and end dates of a new cycle HR are setting up and disabling the save button if any dates in either list match.

I understand the basics of Sequence, but not sure if this is the best function to achieve what I want, nor how apply it in this context.

I have attached a screenshot of the screen I've built for this which should hopefully give some context. You'll see the Yellow/Red colours on the items in the gallery on the left, these are two cycles that are currently 'live'.

Any help will be greatly appreciated.

CycleSettingScreen.png
Categories:
  • v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @CamH-NZQA ,

     

    Though I don't really understand your data source, the logic of comparing dates and checking if overlapping exists may be helpful to you.

     

    For DisplayMode property of the Button, if any overlap is found, it should be disabled, otherwise it's editable. So, the formula could be:

    If(IsEmpty(Filter(YourDB, StartDate > EndDatePicker.SelectedDate || EndDate < StartDatePicker.SelectedDate)), DisplayMode.Edit, DisplayMode.Disabled)

     

    Best regards,

  • CamH-NZQA Profile Picture
    8 on at

    Thank you for your suggestion @v-jefferni . Unfortunately, this doesn't seem to work. This disables the button no matter what dates are entered in the form.

    What I would like to achieve is preventing the submission of a new item where the date range in the form overlaps with any of the date ranges in the gallery/data source. I realise now that I may have over-explained in my original post.

    I've attached a screenshot of the data source.

    Cycle_Datasource.png
  • Verified answer
    v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @CamH-NZQA ,

     

    Just need to reverse the logic of my formula:

    If(IsEmpty(Filter(YourDB, StartDate > EndDatePicker.SelectedDate || EndDate < StartDatePicker.SelectedDate)), DisplayMode.Disabled, DisplayMode.Edit)

     

    Best regards,

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 221 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 120

Last 30 days Overall leaderboard