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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / dealing with time and ...
Power Apps
Answered

dealing with time and schedules

(0) ShareShare
ReportReport
Posted on by 353

I've built an app to help with security guards doing routine patrols on a night shift (or not doing them more like).

 

The first page shows the list of patrols. 

 

nick9one1_0-1669928151611.png

 

the data come from this dataverse table

nick9one1_1-1669928234063.png

 

I need to create collection for each of the rows, indexing when each patrol should start.  

 

e.g. 1st floor patrol

 

Start

End

9PM10pm
10pm11pm

11pm

12pm
12pm

1am

1am2am
  

 

this would ideally be done in a forall loop, but that doesn't seem to be possible.

 

Are there any other solutions to this problem?

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @nick9one1 ,

     

    I made a sample for you:

     

    This is the data in Dataverse.

    vxiaochenmsft_0-1669960923274.png

     

     

    Add a button to the app and set 'OnSelect' as follows.

    Clear(Col1st);ForAll(Sequence(Hour(LookUp(SJT9S,Name="1st floor").'end time')+24-Hour(LookUp(SJT9S,Name="1st floor").'start time'),0),Collect(Col1st,{Start:(Text(DateAdd(LookUp(SJT9S,Name="1st floor").'start time',ThisRecord.Value,Hours),ShortTime)),End:(Text(DateAdd(LookUp(SJT9S,Name="1st floor").'start time',ThisRecord.Value+1,Hours),ShortTime))}))

    vxiaochenmsft_1-1669960923277.png

     

     

    Add a table to view all the data in the collection.

    vxiaochenmsft_2-1669960923279.png

     

    Best Regards,

    Wearsky

  • nick9one1 Profile Picture
    353 on at

    Thank you, thats almost exactly what I need. 

    The list of patrols is dynamic, so I really need the formula to handle all of them. 

    Would it be possible to have the formula output something like this?

     

     

    nick9one1_0-1669970594096.png

     



  • nick9one1 Profile Picture
    353 on at

    this almost works, but only returns the first patrol

     

     

     

    Clear(col_schedule);
    ForAll(
     NFC_Sequence_Mains As OuterLoop,
     
     ForAll(
     Sequence(
     Hour(
     LookUp(
     NFC_Sequence_Mains,
     Name = OuterLoop.Name
     ).'end time'
     ) + 24 - Hour(
     LookUp(
     NFC_Sequence_Mains,
     Name = OuterLoop.Name
     ).'start time'
     ),
     0
     ),
     Collect(
     col_schedule,
     {
     Start: (Text(
     DateAdd(
     LookUp(
     NFC_Sequence_Mains,
     Name = OuterLoop.Name
     ).'start time',
     ThisRecord.Value,
     Hours
     ),
     ShortTime
     )),
     End: (Text(
     DateAdd(
     LookUp(
     NFC_Sequence_Mains,
     Name = OuterLoop.Name
     ).'start time',
     ThisRecord.Value + 1,
     Hours
     ),
     ShortTime
     )),
     Patrol: OuterLoop.Name
     
     }
     )
     )
    )

     

     

     

     

     

    nick9one1_1-1669971482413.png

     

  • v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @nick9one1 ,

     

    If you only have three rows of data, you can use ForAll() three times in the formula.

     

    I made a sample for you.

     

    Clear(Col1st);

    ForAll(Sequence(Hour(LookUp(SJT9S,Name="1st floor").'end time')+24-Hour(LookUp(SJT9S,Name="1st floor").'start time'),0),Collect(Col1st,{Start:(Text(DateAdd(LookUp(SJT9S,Name="1st floor").'start time',ThisRecord.Value,Hours),ShortTime)),End:(Text(DateAdd(LookUp(SJT9S,Name="1st floor").'start time',ThisRecord.Value+1,Hours),ShortTime)),Patrol:LookUp(SJT9S,Name="1st floor").Name}));

    ForAll(Sequence(Hour(LookUp(SJT9S,Name="Car Park").'end time')+24-Hour(LookUp(SJT9S,Name="Car Park").'start time'),0),Collect(Col1st,{Start:(Text(DateAdd(LookUp(SJT9S,Name="Car Park").'start time',ThisRecord.Value,Hours),ShortTime)),End:(Text(DateAdd(LookUp(SJT9S,Name="Car Park").'start time',ThisRecord.Value+1,Hours),ShortTime)),Patrol:LookUp(SJT9S,Name="Car Park").Name}));

    ForAll(Sequence(Hour(LookUp(SJT9S,Name="Ground Floor").'end time')+24-Hour(LookUp(SJT9S,Name="Ground Floor").'start time'),0),Collect(Col1st,{Start:(Text(DateAdd(LookUp(SJT9S,Name="Ground Floor").'start time',ThisRecord.Value,Hours),ShortTime)),End:(Text(DateAdd(LookUp(SJT9S,Name="Ground Floor").'start time',ThisRecord.Value+1,Hours),ShortTime)),Patrol:LookUp(SJT9S,Name="Ground Floor").Name}));

    vxiaochenmsft_0-1669973379677.png

     

     

    Click the button to create a collection.

    vxiaochenmsft_1-1669973379681.png

     

    Best Regards,

    Wearsky

  • nick9one1 Profile Picture
    353 on at

    Sorry my mistake. the code I posted does work 🙄

    I was looking at the collection preview which only shows 5 rows 

    Clear(col_schedule);ForAll(NFC_Sequence_Mains As OuterLoop,ForAll(Sequence(Hour(LookUp(NFC_Sequence_Mains,Name=OuterLoop.Name).'end time')+24-Hour(LookUp(NFC_Sequence_Mains,Name=OuterLoop.Name).'start time'),0),Collect(col_schedule,{Start:(Text(DateAdd(LookUp(NFC_Sequence_Mains,Name=OuterLoop.Name).'start time',ThisRecord.Value,Hours),ShortTime)),End:(Text(DateAdd(LookUp(NFC_Sequence_Mains,Name=OuterLoop.Name).'start time',ThisRecord.Value+1,Hours),ShortTime)),Patrol:OuterLoop.Name})))

     

    nick9one1_0-1669973642378.png

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 326 Most Valuable Professional

#2
11manish Profile Picture

11manish 168

#3
sannavajjala87 Profile Picture

sannavajjala87 75 Super User 2026 Season 1

Last 30 days Overall leaderboard