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

Re: Counting sums grouped by item

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

Re: Counting sums grouped by item

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

Re: Counting sums grouped by item

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

Re: Counting sums grouped by item

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

Re: Counting sums grouped by item

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

Re: Counting sums grouped by item

Hi @cpolito ,

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

Highlighted
Helper I
Helper I

Re: Counting sums grouped by item

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
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,406)