cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Counting sums grouped by item

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"
        )
    )
) 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

6 REPLIES 6
Super User III
Super User III

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:

Filter(AddColumns(
GroupBy(YourTableName,"Hours","crew_id","task","SumHours"),
"TotalHours", Sum(SumHours,Hours)),TotalHours>23)
 
You can change TotalHours>23 to the number of hours needed
 

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.

View solution in original post

Community Support
Community Support

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
        )
    )
)

 Snipaste_2020-03-04_16-56-16.png

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
))

Helpful resources

Announcements
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (6,577)