I have a single table that contains the following fields
crew_id
date
task
hours
A single crew member can have multiple tasks that take different hours of the day.
I want to write a formula that will tell me then number of crew members that have over 23 hours in a single day.
So far I have something like the following, but it's not right. Any ideas?
Sum(
CountRows(
GroupBy(
Filter(
MyTimeEntries,
Text(
tc_date,
DateTimeFormat.ShortDate
) = Text(
DateAdd(
Now(),
VarDateChange
),
DateTimeFormat.ShortDate
)
),
"crew_id",
"hours"
)
)
)
Solved! Go to Solution.
Hi @cpolito ,
Update - my first post code will show all hours - if you need only those 23 or more, try
Filter(
AddColumns(
GroupBy(
Filter(
MyTimeEntries,
DateDiff(
tc_date,
Now(),
Days
)=0
),
"crew_id",
"DayHours"
),
"TotalHours",
Sum(
DayHours,
hours
)
),
TotalHours >=23
)
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.
Hi @cpolito
I cannot test this and there may be delegation issues with the date query (as in yours), but try this
AddColumns(
GroupBy(
Filter(
MyTimeEntries,
DateDiff(
tc_date,
Now(),
Days
)=0
),
"crew_id",
"DayHours"
),
"TotalHours",
Sum(
DayHours,
hours
)
)
DayHours and TotalHours can be whatever names you want - the rest refer to your data.
Your gallery fields will be ThisItem.crew_id and ThisItem.TotalHours
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.
You can try this on the item property of your Gallery:
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.
Hi @cpolito ,
Update - my first post code will show all hours - if you need only those 23 or more, try
Filter(
AddColumns(
GroupBy(
Filter(
MyTimeEntries,
DateDiff(
tc_date,
Now(),
Days
)=0
),
"crew_id",
"DayHours"
),
"TotalHours",
Sum(
DayHours,
hours
)
),
TotalHours >=23
)
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.
Hi @cpolito
Do you want to check if only today's total hours over 23 hours or any single day?
If you want to check total hours in any single day, please try this:
Add the following codes to Screen OnVisble or Button OnSelect to trigger. MyCol collection stores all crew_id that meet the condition that total hours are over 23 hours in a single day.
Then, just use CountRows(MyCol) to get the number.
Clear(MyCol);
ForAll(
GroupBy(
MyTimeEntries,
"crew_id",
"HoursGroup"
),
If(
!IsEmpty(
Filter(
AddColumns(
GroupBy(
AddColumns(HoursGroup,"Date1",Text(tc_date,DateTimeFormat.ShortDate)),
"Date1",
"sum"
),
"TotalHour",
Sum(
sum,
hours
)
),
TotalHour > 23
)
),
Collect(
MyCol,
crew_id
)
)
)
Hope this helps.
Sik
Hi @cpolito ,
Many options here - just go with the one best for you and tag whoever you want to continue the thread with.
That did it.. I needed to add a count rows but worked like a charm!
Thank you!
CountRows(
Filter(
AddColumns(
GroupBy(
Filter(
MyTimeEntries,
DateDiff(
tc_date,
DateAdd(
Now(),
VarDateChange
),
Days
)=0
),
"crew_id",
"DayHours"
),
"TotalHours",
Sum(
DayHours,
hours
)
),
TotalHours >=23
))
Stay up tp date on the latest blogs and activities in the community News & Announcements.
Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
User | Count |
---|---|
203 | |
187 | |
81 | |
50 | |
37 |
User | Count |
---|---|
294 | |
248 | |
123 | |
74 | |
55 |