cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Blacksmith354
Frequent Visitor

Count items in list grouped by a column

I'd like to count the SharePoint list items based on a column.

 

Employee
John
Scott
John

 

I'd like to visualize this in a data table like this:

 

EmployeeItems
John2
Scott1

 

Is this possible without any delegation limits.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
vermaaman
Resolver I
Resolver I

Assuming you are using DataTable control. 


You can use AddColumn & GroupBy function to achieve this. I have tried this formula and it worked for me.

AddColumns(
    GroupBy(
        SPOList,
        "Employees",
        "ID"
    ),
    "Count",
    CountRows(ThisRecord.ID)
)

 

Progressing?  Thumbs Up
Resolved your problem?  Accept as Solution

Helped others as well ?  Accept as Solution

View solution in original post

CNT
Super User
Super User

@Blacksmith354 Use the following formula

ClearCollect(colEmployeeCount, AddColumns(GroupBy(EmployeeList, "Employee", "EmployeeGroup" ), "EmployeeCount", CountRows(EmployeeGroup)))

 But remember GroupBy is not delegable. To avoid that you can filter the data before grouping. If that's not an option, collect all the data into a collection before applying the GroupBy.

View solution in original post

4 REPLIES 4
vermaaman
Resolver I
Resolver I

Assuming you are using DataTable control. 


You can use AddColumn & GroupBy function to achieve this. I have tried this formula and it worked for me.

AddColumns(
    GroupBy(
        SPOList,
        "Employees",
        "ID"
    ),
    "Count",
    CountRows(ThisRecord.ID)
)

 

Progressing?  Thumbs Up
Resolved your problem?  Accept as Solution

Helped others as well ?  Accept as Solution

CNT
Super User
Super User

@Blacksmith354 Use the following formula

ClearCollect(colEmployeeCount, AddColumns(GroupBy(EmployeeList, "Employee", "EmployeeGroup" ), "EmployeeCount", CountRows(EmployeeGroup)))

 But remember GroupBy is not delegable. To avoid that you can filter the data before grouping. If that's not an option, collect all the data into a collection before applying the GroupBy.

Blacksmith354
Frequent Visitor

@vermaaman  and @CNT thank you both. I guess I wasn't specific enough with my request and what exactly I'm trying to do, my apologies.

 

This worked, but now I can't filter records based on the date column. I'd like to have a count of items but be able to filter based on dates. If I'm using a dropdown of the distinct dates, how can I use this?

@Blacksmith354 Use the following formula to filter by date before grouping.

ClearCollect(colEmployeeCount, AddColumns(GroupBy(Filter(EmployeeList, myDate=Now()), "Employee", "EmployeeGroup" ), "EmployeeCount", CountRows(EmployeeGroup)))

Replace myDate with the data column in your SP list and Now() by the date you want to filter. E.g. if the user is selecting a date from a data picker, you can say DatePicker1.SelectedDate.

Hope that helps.🤔 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (2,345)