web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : IJos4TPm0i5f650D6Pz9U2
Power Apps - Building Power Apps
Answered

If Statement to Prevent Double Bookings in App

Like (0) ShareShare
ReportReport
Posted on 13 Jul 2023 13:22:46 by 658

Hi,

 

I am creating an equipment booking app and I would like it so when the form is submitted, the app checks to see if the start date and time and end date and time selected already exists for that choice from the drop down box. If it does exist, I would like the app to throw up an error and say this date and time for choice 'x' already exists.

 

Thanks in advance.

I have the same question (0)
  • BCBuizer Profile Picture
    22,317 Super User 2025 Season 2 on 24 Aug 2023 at 23:02:02
    Re: If Statement to Prevent Double Bookings in App

    Hi @BS10,

     

    I think the issue is because of the semicolon you inserted: 

    BCBuizer_0-1692918062422.png

    I think it should be a comma, but it's hard to check since you sent a picture and the formula is not properly formatted.

  • BS10 Profile Picture
    658 on 24 Aug 2023 at 22:46:37
    Re: If Statement to Prevent Double Bookings in App

    Hi @BCBuizer,

     

    Thank you for the fast response. I have tried this below but I get 1 error in the formula which says, unexpected characters. I have added a checkbox which needs to be ticked by the user and an approval flow too, just to let you know.


    I have added pictures of the code as when I was trying to reply with the HTML the site said it was invalid and removed some of the code. Please let me know if these pictures are ok.

     

    IMG_2194.jpeg

    IMG_2196.jpeg

     

    Thank you!

  • BCBuizer Profile Picture
    22,317 Super User 2025 Season 2 on 24 Aug 2023 at 19:37:12
    Re: If Statement to Prevent Double Bookings in App

    Hi @BS10 ,

     

    Because of this the structure of the formula needs to be changed a bit, but I think the below should do the trick:

    With(
    	{_SelectedStartTime: DateTimeValue($"{DateValue1.SelectedDate} {HourValue1.Selected.Value}:{MinuteValue1.Selected.Value}"),
    	_SelectedEndTime: DateTimeValue($"{DateValue2.SelectedDate} {HourValue2.Selected.Value}:{MinuteValue2.Selected.Value}")},
    	If(
    		_SelectedStartTime >= _SelectedEndTime,
    		Notify(
    			"The selected end date/time is before or equal to the selected start date/time",
    			NotificationType.Error
    		),
    		IsBlank(
    			LookUp(
    				BookLaptopTrolley,
    				'Laptop Trolley Name'.Value = DataCardValue7.Selected.Value &&
    				((_SelectedStartTime >= 'Start Time' && _SelectedStartTime < 'End Time') ||
    				(_SelectedEndTime > 'Start Time' && _SelectedEndTime <= 'End Time') ||
    				(_SelectedStartTime <= 'Start Time' && _SelectedEndTime >= 'End Time'))
    			)
    		),
    		SubmitForm(EditForm1),
    		Notify(
    			"This equipment is already taken out at that time",
    			NotificationType.Error
    	)
    )

     

    For further new questions, please open a new topic so it is easier for other members of the community to find the answers their similar questions.

  • BS10 Profile Picture
    658 on 24 Aug 2023 at 16:18:09
    Re: If Statement to Prevent Double Bookings in App

    Hi @BCBuizer,

     

    I have just encountered a bug with the app, I just noticed I have managed to book equipment with the end time which is earlier than the start time. Could you please advise on an if statement to prevent this from happening? 

    Thanks in advance! 

  • BCBuizer Profile Picture
    22,317 Super User 2025 Season 2 on 18 Jul 2023 at 12:08:10
    Re: If Statement to Prevent Double Bookings in App

    HI @BS10 ,

     

    Simply add a Filter to the Items property of the gallery to only show the items where 'End Time' > Now()

     

  • BS10 Profile Picture
    658 on 18 Jul 2023 at 10:59:41
    Re: If Statement to Prevent Double Bookings in App

    Hi @BCBuizer ,

     

    Apologies but I have 1 more question if that's ok, would it be possible for bookings which have 'expired' or 'completed' to not be shown in the gallery? I assume I will need to maybe setup another SharePoint column for this? Or would it be easier to create a 'Previous Bookings' screen and then filter bookings into this gallery?

     

    Thanks

  • BS10 Profile Picture
    658 on 18 Jul 2023 at 10:05:54
    Re: If Statement to Prevent Double Bookings in App

    Hi @BCBuizer ,

     

    Thank you very much, I really appreciate the help.

  • BCBuizer Profile Picture
    22,317 Super User 2025 Season 2 on 18 Jul 2023 at 10:03:21
    Re: If Statement to Prevent Double Bookings in App

    Hi @BS10 ,

     

    Yes, it is possible to set a default selected item for HourValue2, by setting the Default property to:

    Text(
     Mod(
     Value(
     HourValue1.Selected.Value
     )+2,
     24
     )
    )
  • BS10 Profile Picture
    658 on 18 Jul 2023 at 09:41:16
    Re: If Statement to Prevent Double Bookings in App

    Hi @BCBuizer ,

     

    Thank you very much for your help! This is now working. 

     

    The trolleys are normally booked out for 2 hour time slots, I would like the HourValue2 to automatically add on 2 hours from the selected hour in HourValue1. Is that possible please?

     

    Thanks 

  • BCBuizer Profile Picture
    22,317 Super User 2025 Season 2 on 18 Jul 2023 at 08:27:26
    Re: If Statement to Prevent Double Bookings in App

    Hi @BS10 ,

     

    The described behaviour is not related to the formula, but rather with the form mode. I suspect the form is in FormMode.Edit when you run the formula, which is why it overwrites the an existing item. The form should be in FormMode.New to create a new item. 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

MS.Ragavendar – Community Spotlight

We are honored to recognize Ragavendar Swaminatha Subramanian as our September…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 892 Most Valuable Professional

#2
Power Apps 1919 Profile Picture

Power Apps 1919 356

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 310 Super User 2025 Season 2

Last 30 days Overall leaderboard