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 / How to prevent users f...
Power Apps
Answered

How to prevent users from registering overlapping hours

(0) ShareShare
ReportReport
Posted on by 39

Hi everyone,

 

I am building an app where users register time and I want to prevent the user from registering overlapping hours. For example, I register hours from 07:00 am to 15:00 pm, now the user is not allowed to register any hours within the period of time that already is posted. I have found one solution that works for the first registered hours by using the function under, but if I register two or more separate registrations then only the first one will trigger the rule. 

 

 

 

 

If(
 /*If starttime is earlier than existing time*/
 Time(
 Value(FromHour_12.SelectedText.Value),
 Value(FromMinute_12.SelectedText.Value),
 0
 ) <= LookUp(
 CalendarEventsGallery1.AllItems,
 !IsBlank(CalendarEventsGallery1.AllItems),
 TimeValue(StartTime)
 ),/*Then*/
 Time(
 Value(FromHour_12.SelectedText.Value),
 Value(FromMinute_12.SelectedText.Value),
 0
 ) <= LookUp(
 CalendarEventsGallery1.AllItems,
 !IsBlank(CalendarEventsGallery1.AllItems),
 TimeValue(StartTime)
 ) && Time(
 Value(ToHour_12.SelectedText.Value),
 Value(ToMinute_12.SelectedText.Value),
 0
 ) <= LookUp(
 CalendarEventsGallery1.AllItems,
 !IsBlank(CalendarEventsGallery1.AllItems),
 TimeValue(StartTime)
 )/*If not*/
,
 Time(
 Value(FromHour_12.SelectedText.Value),
 Value(FromMinute_12.SelectedText.Value),
 0
 ) >= LookUp(
 CalendarEventsGallery1.AllItems,
 !IsBlank(CalendarEventsGallery1.AllItems),
 TimeValue(EndTime)
 ),
 Time(
 Value(FromHour_12.SelectedText.Value),
 Value(FromMinute_12.SelectedText.Value),
 0
 ) >= LookUp(
 CalendarEventsGallery1.AllItems,
 !IsBlank(CalendarEventsGallery1.AllItems),
 TimeValue(EndTime)
 ) && Time(
 Value(ToHour_12.SelectedText.Value),
 Value(ToMinute_12.SelectedText.Value),
 0
 ) >= LookUp(
 CalendarEventsGallery1.AllItems,
 !IsBlank(CalendarEventsGallery1.AllItems),
 TimeValue(EndTime)
 )
 ),Edit,Disabled

 

 

 

 

As you can see from the pictures below, I have to registrations, and now I am not supposed to be able to register hours between 15:30 and 18:30, but "Ferdig" is not disabled. 

 

CathrineB_0-1596534224247.png

CathrineB_1-1596534300084.png

 

Thank you,

 

Best,

 

Cathrine

 

Categories:
I have the same question (0)
  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @CathrineB :

    Do you hope that as long as the start or end time selected by the user is between the start and end time of any record in CalendarEventsGallery1.AllItems, the record cannot be submitted?

    My method is to traverse all the records in CalendarEventsGallery1.AllItems:
    1. If the start or end time selected by the user is between the start and end time of a record, a record {Value:1} will be returned.
    2. Calculate the number of records returned. If the number of records returned is greater than 1, the condition is not met (disabled the'Ferding')

    Please try this code:

     

    If(
    CountRows(
    ForALL(CalendarEventsGallery1.AllItems,
     If(
     (Time(Value(FromHour_12.SelectedText.Value),Value(FromMinute_12.SelectedText.Value),0)<TimeValue(StartTime) && Time(Value(FromHour_12.SelectedText.Value),Value(FromMinute_12.SelectedText.Value),0)>TimeValue(EndTime)) 
     Or 
     (Time(Value(ToHour_12.SelectedText.Value),Value(ToMinute_12.SelectedText.Value),0)<TimeValue(StartTime) && Time(Value(ToHour_12.SelectedText.Value),Value(ToMinute_12.SelectedText.Value),0)>TimeValue(EndTime)),
     {Value:1}
     )
     ))>=1,Disabled,Edit)

     

    If the solution cannot solve your problem, can you provide more specific requirements and details about your app.(Especially the data structure of CalendarEventsGallery1.AllItemss)

    Best Regards,

    Bof

  • Verified answer
    CathrineB Profile Picture
    39 on at

    Hi @v-bofeng-msft,

     

    Thank you for your helpful reply. I was able to achieve a satisfying result by making a few changes to your suggestion. I used the CountIf function instead of CountRows to check if any of the rows contains {Value:1} and added another link in the syntax preventing the user from submitting hours if they selected hours before and after as well. 

     

     If(CountIf(
     ForAll(
     CalendarEventsGallery1_1.AllItems,
     If(
     (Time(
     Value(FromHour_15.SelectedText.Value),
     Value(FromMinute_15.SelectedText.Value),
     0
     ) > TimeValue(StartTime) && Time(
     Value(FromHour_15.SelectedText.Value),
     Value(FromMinute_15.SelectedText.Value),
     0
     ) < TimeValue(EndTime)) Or (Time(
     Value(ToHour_15.SelectedText.Value),
     Value(ToMinute_15.SelectedText.Value),
     0
     ) > TimeValue(StartTime) && Time(
     Value(ToHour_15.SelectedText.Value),
     Value(ToMinute_15.SelectedText.Value),
     0
     ) < TimeValue(EndTime)) Or (Time(
     Value(FromHour_15.SelectedText.Value),
     Value(FromMinute_15.SelectedText.Value),
     0
     ) < TimeValue(StartTime) && Time(
     Value(ToHour_15.SelectedText.Value),
     Value(ToMinute_15.SelectedText.Value),
     0
     ) > TimeValue(EndTime)),
     {Value: 1},
     {Value: 0}
     )
     ),
     Value > 0
     ) >= 1,
     Disabled,
     Edit
    )

     

    Best,

     

    Cathrine

  • PapithaSekar Profile Picture
    54 on at

    Hi,

     

    I am working with same condition, for me i need to notify user if the selected time overlapped with registered time. can you help me with the logic?

     

     

    Skjermbilde_tid.PNG

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 356 Most Valuable Professional

#2
11manish Profile Picture

11manish 225 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 211

Last 30 days Overall leaderboard