Hi, I've been trying to filgure this out for longer than I care to admit. I've tried multiple different ways but have yet to solve it.
I have a SP list, I'm using GET ITEMS to bring it in and using an ODATA query to pull in only rows that are null in one column. This part is working fine, I have a compose to check the length of the output at this stage.
Next I need to filter the data again and group it by a line manager email field (single line of text), then also group it by head of department email field. After all this I need to output it to a HTML table, grouped by their line manager reports which will be emailed to each of the HODs, none of them will see the other departments data, only their own.
I have got the emails working to send to the first line managers and its outputting to HTML table. But I'm really struggling to get it to next level head of department, grouping their line managers data and outputting only a count of how many rows their are for each line manager in their department.
This is my Line manager flow (which is working):

The second Get items filters for the same null value in one column as the first Get Items, and also checks for the line manager email match from the COMPOSE EMAIL TO step just above it.
My HOD flow only needs to count the number of rows per line manager within their department, no detail is required. Am I missing a really simple way to do this?
My goal is to have an email going out to each department head containing a HTML table which has a list of the line managers that report to them along with a count of the rows related to them from the SP list.
Any help much appreciated, I've followed several youtube videos from Reza Dorrani, articles by Matthew Devenney, all have been fantastic but I just can't work this flow out.