I will use some assumptions to describe one scenario how to calculate costs.
I assume you are using Logged by dimension for counting Hours spent for Departments by listing set of users in each of them.
Here is an example fomula how to calculate costs using Logged by imported property Rate by particular group of users, including time spent on linked issues. This is example for Story issues with linked Bugs, imported as property.