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
Super User
Super User

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

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

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 (3,084)