In addition to @DamoBird365 brilliant solution. Here is another possible way, which achieves the same result, in a slightly different way. It's always interesting to see different solutions to the same problem:
https://ibb.co/27XrLTZ

I have copied the whole thing into a scope for you so you can easily copy it into your flow to see how it works. It requires no variables and should execute very fast. To add it your flow:
- Copy the code below into your clipboard
- Choose Add an action.
- Go to my clipboard.
- Press CTRL-V
- Select the new scope action that appears.
{"id":"e607692e-65e8-4977-804e-7339-2672065d","brandColor":"#8C3900","connectionReferences":{},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Scope","operationDefinition":{"type":"Scope","actions":{"Array":{"type":"Compose","inputs":[{"Name":"Person A","EmpNumber":"111111","Time":"0005"},{"Name":"Person B","EmpNumber":"222222","Time":"0010"},{"Name":"Person A","EmpNumber":"111111","Time":"0015"},{"Name":"Person B","EmpNumber":"222222","Time":"0008"}],"runAfter":{}},"Select":{"type":"Select","inputs":{"from":"@outputs('Array')","select":"@removeProperty(item(), 'Time')"},"runAfter":{"Array":["Succeeded"]},"description":"removeProperty(item(), 'Time')"},"Unique_People":{"type":"Compose","inputs":"@union(body('Select'),body('Select'))","runAfter":{"Select":["Succeeded"]},"description":"union(body('Select'),body('Select'))"},"Apply_to_each":{"type":"Foreach","foreach":"@outputs('Unique_People')","actions":{"Filter_array":{"type":"Query","inputs":{"from":"@outputs('Array')","where":"@equals(item()['EmpNumber'], items('Apply_to_each')['EmpNumber'])"},"runAfter":{},"description":"items('Apply_to_each')['EmpNumber']"},"TotalTime":{"type":"Compose","inputs":"@addProperty(items('Apply_to_each'), 'Time', xpath(xml(json(concat('{ \"root\": {\"People\": ', body('Filter_array'), '}}'))), 'sum(*//Time/text())'))","runAfter":{"Filter_array":["Succeeded"]},"description":"addProperty(items('Apply_to_each'), 'Time', xpath(xml(json(concat('{ \"root\": {\"People\": ', body('Filter_array'), '}}'))), 'sum(*//Time/text())'))"}},"runAfter":{"Unique_People":["Succeeded"]}},"Agrregated":{"type":"Compose","inputs":"@outputs('TotalTime')","runAfter":{"Apply_to_each":["Succeeded"]}}},"runAfter":{}}}
See how you get on.
Blog: tachytelic.net
YouTube: https://www.youtube.com/c/PaulieM/videos
If I answered your question, please accept it as a solution 😘