I have a gallery formatted as a table which gives a run down of hours worked for different departments in my organization stored in CDS. Right now the table looks something like this:
District | Role | Hours |
West | HR | 5 |
West | IT | 10 |
East | HR | 14 |
West | IT | 20 |
The Items property of this gallery is filtering all items from an Employees entity where Hours is greater than 0:
Filter(Employees,HoursWorked > 0)
The district, role, and hours values are all fields in my Employee entity.
As a next step, I'd like to simplify the table so that if the District and Role are the same, the Hours column will show a total for all employees, like this:
District | Role | Hours |
West | HR | 5 |
West | IT | 30 |
East | HR | 14 |
I'm not really sure how to approach this. I was trying to iterate through the Employees table and build a collection conditionally checking if the District and Role already exist, but as this is just a subset of the data for all employees this feels inefficient. I also tried group by but as District AND Role are relevant, I'm not quite sure how to do that. Is there any other way to manipulate the Filter to sum the Hours column?
Solved! Go to Solution.
Needed to add the field to the group by. My final Items value ended up as:
GroupBy(
Filter(
Employees,
HoursWorked > 0
),
"District",
"Role",
"VisitSum"
)
Make use of Groupby functions. Video from Brian Knight
https://youtu.be/q42ibovAqZc
Also:
If you like this reply, please give kudos. And if this solves your problem, please accept this reply as the solution.
Thank you for the response. The total hours is working but I am not able to access ThisItem.Role
Needed to add the field to the group by. My final Items value ended up as:
GroupBy(
Filter(
Employees,
HoursWorked > 0
),
"District",
"Role",
"VisitSum"
)
User | Count |
---|---|
176 | |
111 | |
86 | |
44 | |
42 |
User | Count |
---|---|
228 | |
116 | |
115 | |
72 | |
67 |