cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SevenWishes
Helper I
Helper I

DisplayMode disabled if between dates

Hi,

I need help to understand why my IF doesn't work in this formula.

 

I have two dates From and To, these dates are selectable:

Name: DatePickerSelectableDateFrom and DatePickerSelectableDateTo

SevenWishes_0-1656409163098.png

 

I also have SharepointList where is date From (upper date) and To (lower date), and those dates are defined by the user

Name:
DatePickerGalleryCheckboxFrom (upper date)

DatePickerGalleryCheckboxTo (lowerdate)

SevenWishes_2-1656407854309.png

I want to disable that gallery checkbox by adding a formula IF selectable dates are between DatePickerSelectableDateFrom and DatePickerSelectableDateTo

So if we have the 27th of June picked as the DatePickerSelectableDateFrom and the 28th of June as the DatePickerSelectableDateTo the Desk 13, 15, and 18 should be disabled and others of them should be enabled.

I already tried:

 

 

 

 

If(DatePickerSelectableDateFrom.SelectedDate <= DatePickerGalleryCheckboxFrom.SelectedDate ||DatePickerSelectableDateTo.SelectedDate.SelectedDate <= DatePickerGalleryCheckboxTo.SelectedDate , DisplayMode.Disabled, DisplayMode.Edit)

 

 

 

 

but it is not working as expected any help with that maybe I should add And not the Or I started to feel confused in here.

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @SevenWishes ,

I think you need this

If(
   (
      DatePickerSelectableDateFrom.SelectedDate >= DatePickerGalleryCheckboxFrom.SelectedDate &&
      DatePickerSelectableDateFrom.SelectedDate.SelectedDate <= DatePickerGalleryCheckboxTo.SelectedDate
   ) ||
   (
      DatePickerSelectableDateTo.SelectedDate.SelectedDate >= DatePickerGalleryCheckboxFrom.SelectedDate && 
      DatePickerSelectableDateTo.SelectedDate.SelectedDate <= DatePickerGalleryCheckboxTo.SelectedDate
   ),
   DisplayMode.Disabled, 
   DisplayMode.Edit
)

 

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

View solution in original post

15 REPLIES 15
jcfDaniel
Super User
Super User

Hi,

 

Could you insert 4 labels and tell me what is return for:

DatePickerSelectableDateFrom.SelectedDate
DatePickerGalleryCheckboxFrom.SelectedDate
DatePickerSelectableDateTo.SelectedDate.SelectedDate
DatePickerGalleryCheckboxTo.SelectedDate

 

 


Regards. JD.

Hi,

Sure.

Thanks for the answer.

 

By following my example I added all labels to a Gallery and have the correct numbers:

DatePickerSelectableDateFrom: 27/06/2022

DatePickerSelectableDateTo: 28/06/2022

 

Now it depends on the item in Sharepoint List:

Desk 13:

DatePickerGalleryCheckboxFrom : 27/06/2022

DatePickerGalleryCheckboxTo: 27/06/2022

 

Desk17

DatePickerGalleryCheckboxFrom: 29/06/2022

DatePickerGalleryCheckboxTo: 01/07/2022

 

Desk18

DatePickerGalleryCheckboxFrom: 27/06/2022

DatePickerGalleryCheckboxTo: 28/06/2022

 

etc

 

I hope this helps.

Thank you

jcfDaniel
Super User
Super User

With no formatting in the labels, like Text(Somedate, "dd/mm/yyy") ?


Regards. JD.
SevenWishes
Helper I
Helper I

Hi,

Not sure I understand what is that for,

So basically the date on the first screenshot the top and lower ones where are desks are datepicker they are not labels, but when added a Label here it is:

SevenWishes_1-1656493221656.png

and results:

 

SevenWishes_0-1656493404768.png

the date is the same as on DatePickerSelectableDateFrom  from the first picture.

 

Regarding dates from Gallery I used LookUp function as they have their own dates in Sharepoint File

DatePickerGalleryCheckboxFrom:

 

 

LookUp('Desk Reservation', DeskText = ThisItem.Title,'Check Out From')

 

 

 

DatePickerGalleryCheckboxTo

 

 

LookUp('Desk Reservation', DeskText = ThisItem.Title,'Check Out To')

 

 

 

The code I looking for regarding Gallery Checkboxes is something similar to this:

DisplayMode:

 

If(DatePickerSelectableDateFrom.SelectedDate = DatePickerGalleryCheckboxFrom.SelectedDate ||
   DatePickerSelectableDateFrom.SelectedDate = DatePickerGalleryCheckboxTo.SelectedDate || 
   DatePickerSelectableDateTo.SelectedDate = DatePickerGalleryCheckboxFrom.SelectedDate || 
   DatePickerSelectableDateTo.SelectedDate = DatePickerGalleryCheckboxTo.SelectedDate, 
   DisplayMode.Disabled, DisplayMode.Edit
  )

 

 

 but this one only disables the date if the SelectableDate is equal to GalleryDate but not between as < or > isn't working correctly or I cannot use it in the right way.

jcfDaniel
Super User
Super User

Hi,

 

I am havinh troubel getting the logic you are trying to implement. Maybe a scenario will help.

 

Is this an app for sheduling Desk? If so don't you just need to check if your starting date is greater than the desk's upper occupation date?

 

I have built an example and I have put it in rthe Text property just to make it easier to read. Please see if I am anywhere near what you are trying to do.

datesbetween.PNG


Regards. JD.

Thanks,

It is very easy to understand.

We have two scenarios:

1. User is booking a desk then providing details which desk is taking and on what dates

lets pick the same date as we did on the first post 27 June to 28 June and Desk number 13

2. After a while other user want to book the same desk first he is trying to pick the same dates, at the message 5 at the end I typed my code to review, so when he is picking up 27 to 28 of June the desk is occupied by someone else, so he is typing again and changing dates 27 of June to 29 June, still occupied. then he is changing the date From to 26 to 29 and it is available. 

 

I hope it has more sense, not sure what else I can provide than the code I already added. 

Thank you for your example and time but it is not working as it is giving me this:
I used the same scenario as you did. 

Date "From " and the latest date in the Gallery, the results seem to be a weird one as it is disabling the desks even after the 28 of June which is wrong, Desk 14, 16, and 17 shouldn't be disabled as per the dates in the checkboxes the Desk 14 was occupied between 30 June to 1 July, Desk 16 - 29 June to 30 June and Desk 17 - 29 June to 1 July. 

SevenWishes_0-1656572845007.png

 

 

 

jcfDaniel
Super User
Super User

You say "changing the date From to 26 to 29 and it is available. "

 

Does this mean that the user wants to book the desk from the 26th through till the 29th or does this mean he wants any of the dates in range, so either the 26th, the 27th, the 28th or the 29th?

 

In the first case, the desk is not available because someone has it for the 27th and the 28th, right?

In the second scenario, the desk is available on the 26th, occupied on the 27th and 28th and then available again on the 29th.

 

Wich one is it?


Regards. JD.
SevenWishes
Helper I
Helper I

I did that desks a little bit larger. This is a gallery all items are placed in Sharepoint List, gallery has DeskName, From, and To dates as we have here on the screen. This data can be patched to Sharepoint List by any user the user needs to pick the date he wants to book the desk.

SevenWishes_1-1656578909996.png

 

Imagine I am a user who wants to Pick Desk 17 between 29 June and 01 July and you are the next person who wants to pick Desk 17 on 30 June only. That desk will be available for you as I have no clue how to make it disable as the desk 17 have two dates 29th and 1 July, I would have to create a variable or code to say that between these two dates there is one more date which is 30 June that is not available for use. But for that, I do not have enough knowledge of how to do this.

 

Btw I created a collection for that, it is giving me a correct list of dates between StartDate and EndDate, if I type 

25th July and enddate 30July it will count all data between it, I only need to add this to Checkbox Gallery as it needs to be equal to this one then if the DatePicker will be equal to checkbox in the gallery all the dates will be correctly disabled.

 

 

 

 

Set(var1stDate,DatePickerSelectableDateFrom.SelectedDate);
Set(var2stDate,DatePickerSelectableDateTo.SelectedDate);
Set(varDifference, DateDiff(var1stDate, var2stDate, Days));

Clear(CollectionDateDiff);
ForAll(Sequence(varDifference +1), Collect(CollectionDateDiff, {Dates: DateAdd(var1stDate,CountRows(CollectionDateDiff),Days)}));

 

 

SevenWishes_1-1656581631082.png

 

SevenWishes_0-1656582421121.png

 

 

 

 

jcfDaniel
Super User
Super User

@SevenWishes I think you may have to take a step back and look at hoe your data is structure and also collect some ideas from the community.

 

Take a look at this amazing video from @RezaDorrani : Top 10 Power Apps Examples (Showcase) - YouTube

 


Regards. JD.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (1,628)