cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
apsuk
Regular Visitor

How to check if a list of dates conflicts with a list date ranges?

Hi

 

I have a Table called DaysToStore. It contains a field called Day that the user has picked.

There is also a Bookings Table, which has 3 fields, a unqiue BookingId, ReservedFrom and ReservedUntil.

I want to set Button1.OnSelect to create a new version of DaysToStore, with an added field called Clash.

 

For each record the value of Clash is either true or false if the Day >= ReservedFrom and Date <= ReservedUntil.

Here is my attempt but it doesn't work, and of course PowerApps is pretty bad and indicating why this might be...

ClearCollect(
NewDaysToStore, AddColumns( DaysToStore, "Clash", LookUp(Bookings, And(Day >= ReservedFrom, Day <= ReservedUntil), true)) 
)

Do you have any suggestions?

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @apsuk ,

Could you please share a bit more about your scenario?

Do you want to add a new Clash field with true or false value to your new DaysToStore table?

 

Based on the formula that you mentioned, I think there is something wrong with it. I have made a test on my side, please consider take a try with the following formula:

ClearCollect(
            NewDaysToStore, 
            AddColumns(
                        DaysToStore, 
                        "Clash", 
                        If(
                           !IsBlank(LookUp(Bookings, Day >= ReservedFrom && Day <= ReservedUntil)),
                           true,
                           false
                        )
            ) 
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
EricLott
Resident Rockstar
Resident Rockstar

I've put together a test on my end and your code is working fine. Double check that DaysToStore.Day, Bookings.ReservedFrom, and Bookins.ReservedUntil are all date types. You can use DateValue() to ensure they are stored as dates.

ClearCollect(
NewDaysToStore, AddColumns( DaysToStore, "Clash", LookUp(Bookings, And(DateValue(Day) >= DateValue(ReservedFrom), DateValue(Day) <= DateValue(ReservedUntil)), true)) 
)
yashag2255
Dual Super User II
Dual Super User II

Hi @apsuk 

 

You can avoid usage of collection in this case by using the below formula:
 
If(CountRows(Filter(Bookings, And(Day >= ReservedFrom, Day <= ReservedUntil))) = 0 ,"false","true")
 
false means that there is no clash but true means that there is a clash.
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
v-xida-msft
Community Support
Community Support

Hi @apsuk ,

Could you please share a bit more about your scenario?

Do you want to add a new Clash field with true or false value to your new DaysToStore table?

 

Based on the formula that you mentioned, I think there is something wrong with it. I have made a test on my side, please consider take a try with the following formula:

ClearCollect(
            NewDaysToStore, 
            AddColumns(
                        DaysToStore, 
                        "Clash", 
                        If(
                           !IsBlank(LookUp(Bookings, Day >= ReservedFrom && Day <= ReservedUntil)),
                           true,
                           false
                        )
            ) 
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,355)