cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted

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
Highlighted
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.

Highlighted

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.

 
 
Highlighted

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

Highlighted
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

Highlighted

Hi @cpolito ,

Many options here - just go with the one best for you and tag whoever you want to continue the thread with.

Highlighted

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

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

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,816)