Skip to main content
Community site session details

Community site session details

Session Id : 26/ji+zdg+nafGYht7Lbtn
Power Apps - Building Power Apps
Unanswered

Distinct group by and counts

Like (0) ShareShare
ReportReport
Posted on 18 Aug 2023 10:27:42 by 1,118

Dear Team, For a SPList, i am trying to group the employees by Department and then get the count of them. Sounds easy. But i have been trying to derive the formula, which is not giving me the expected result.

 

 

Employee1650Information Technology11413
Employee2651Information Technology11323
Employee2651Information Technology11322
Employee1650Information Technology11413
Employee1650Information Technology11413
Employee2651Information Technology11323
Employee1650Information Technology11413
Employee2651Information Technology11321
Employee1650Information Technology11413
Employee2651Information Technology11321
Employee2651Information Technology11322
Employee1650Information Technology11413
Employee1650Information Technology11412
Employee2651Information Technology11322
Employee2651Information Technology11323
Employee1650Information Technology11412
Employee2651Information Technology11323
Employee1650Information Technology11412
Employee2651Information Technology11322
Employee1650Information Technology11412
Employee1650Information Technology11411

 

 

AddColumns(Distinct(Filter(SPList,HodFlag ="Completed"),EmpDept),"CountDept",CountRows(Distinct(Filter(SPList,HodFlag ="Completed"),EmpDept)

 

 

my gallery should show me something like this. But i am getting count as 1 instead of 2.

There are two employees in Information Technology. So gallery rows will be displaying Department Names, and the Employee count on it.

You can ignore the HOD flag column as i have just made this column to make sure this record is verified by head of the department.

 

venka91_0-1692353166701.png

Later tried the formula.

 

 

AddColumns(GroupBy(AWPR_Responses,"EmpDept","DeptGroup"),"EmpCount",CountRows(Distinct(ThisRecord.DeptGroup,EmpFullName)))

 

 

Giving me the result in the gallery as

 

venka91_1-1692354417194.png

Please help to validate it ?

 

 

  • developerAJ Profile Picture
    2,855 on 19 Aug 2023 at 04:30:57
    Re: Distinct group by and counts

    thisrecord.deptgroup and saying deptgroup

     

    thisrecord.deptgroup is something you need to use in forall it respresent single item

     

    deptgroup is table.

     

     

  • venka91 Profile Picture
    1,118 on 18 Aug 2023 at 11:35:23
    Re: Distinct group by and counts

    Just for my understanding, is there any change between thisrecord.deptgroup and saying deptgroup alone ?

  • developerAJ Profile Picture
    2,855 on 18 Aug 2023 at 11:21:54
    Re: Distinct group by and counts
    AddColumns(GroupBy(AWPR_Responses,"EmpDept","DeptGroup"),"EmpCount",CountRows(Distinct(DeptGroup,EmpFullName)))

     

    this should do just change thisitem.deptgroup to deptgroup

     

  • gcmfaizan Profile Picture
    1,022 on 18 Aug 2023 at 10:40:47
    Re: Distinct group by and counts

    Hi @venka91 ,

     

    for example here is my employee data:

    ClearCollect(
     colEmployees,
     Table(
     { EmployeeName: "John", Department: "HR", Salary: 50000 },
     { EmployeeName: "Jane", Department: "IT", Salary: 60000 },
     { EmployeeName: "Michael", Department: "Finance", Salary: 55000 },
     { EmployeeName: "Emily", Department: "IT", Salary: 62000 },
     { EmployeeName: "David", Department: "HR", Salary: 48000 },
     { EmployeeName: "Sara", Department: "Finance", Salary: 58000 },
     { EmployeeName: "Daniel", Department: "IT", Salary: 61000 }
     )
    )

     

    and here is the formula to count the employee as per Department:

    ClearCollect(
     colDepartmentCounts,
     AddColumns(
     GroupBy(colEmployees, "Department", "Group"),
     "Temp_Department",
     Group,
     "Temp_Count",
     CountRows(Group)
     )
    )

     

    here is the output:

    gcmfaizan_0-1692355236164.png

     

    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete