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

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (16,904)