I have a table containing Resource Name, Resources Owner, Project Name, Project Manager, Effort. For Every resource owner, I want to calculate the loaned out efforts(efforts spe
There are 3 types of effort in your question:
The easiest type of effort is "not loaned or borrowed effort" - where the manager you care about is both the resource owner and the project manager (i.e. they are using resources they manage on a project they manage).
The next type of effort is "loaned effort" - where the manager you care about is the resource owner but not the project manager (i.e. the manager's resources are being used on someone else's project).
The final type of effort is "borrowed effort" - where the manager you care about is the project manager but not the resource owner (i.e. they are using someone else's resources on their project).
You have loaned effort defined correctly, but it's based on the assumption that the resource owner is the manager you care about. Indeed, your Loaned Effort calculation is perfectly correct for Borrowed Effort too, except you would need to display the table by Project Manager instead of Resource Owner (this is because Project Managers borrow and Resource Owners lend - but otherwise it's the same calculation).
The essence of your problem is, therefore, not to a problem with the calculation, but rather because you want to display the "borrowed" and "loaned" number side-by-side for the same person.
To accomplish this, I recommend having a separate, de-duped table of managers that you can calculate the borrowed and loaned number for. One of the main reasons for doing this is because a manager may borrow but never lend. If you start with the premise of resource owners (who lend), the manager who borrows but never lends will never appear in your results.
I called this table DimManager, with a single column Manager. You can obviously vary this. I did not relate this table to All_Activity Data:
Then, for the measures, I started with not loaned or borrowed, where I want the manager to be both the project manager and the resource owner:
Not Loaned or Borrowed =
SUMX (
'DimManager',
CALCULATE (
SUMX (
FILTER (
'All_Activity Data',
'All_Activity Data'[Project Manager] = MAX ( 'DimManager'[Manager] )
&& 'All_Activity Data'[Resource Owner] = MAX ( 'DimManager'[Manager] )
),
'All_Activity Data'[Logged Effort]
)
)
)
Working from the inside out, the FILTER is what is doing the join between the two unrelated tables. In this case saying that I want the Manager to be both the Project Manager and the Resource Owner. The nested SUMX(CALCULATE(SUMX is so that, when calculating a column total, it sums the result of each individual manager. Without this, the measure would use the MAX(Manager) for the column totals, making the column totals the same as Manager X in your sample data. I learnt about this trick from Matt Allington: https://exceleratorbi.com.au/double-calculate-solves-sumx-problem/
For your loaned and borrowed calculations, they are exactly the same as above, except instead of saying you want both your Resource Owner and Project Manager to match your manager, one of them does not match your manager:
Loaned =
SUMX (
'DimManager',
CALCULATE (
SUMX (
FILTER (
'All_Activity Data',
'All_Activity Data'[Project Manager] <> MAX ( 'DimManager'[Manager] )
&& 'All_Activity Data'[Resource Owner] = MAX ( 'DimManager'[Manager] )
),
'All_Activity Data'[Logged Effort]
)
)
)
'
Borrowed =
SUMX (
'DimManager',
CALCULATE (
SUMX (
FILTER (
'All_Activity Data',
'All_Activity Data'[Project Manager] = MAX ( 'DimManager'[Manager] )
&& 'All_Activity Data'[Resource Owner] <> MAX ( 'DimManager'[Manager] )
),
'All_Activity Data'[Logged Effort]
)
)
)
This results in the final result below: