Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
What is the best way to write a measure to calculate sum of amount from Opportunity where the current user is either the owner of the Opportunity(Parent) or on the Opportunity Team(child)?
Here are the two tables and the result the measure should return.
Opportunity:
Opportunity ID | Amount | Opportunity Owner Email |
1 | 100 | |
2 | 200 | |
3 | 300 |
Opportunity Team:
Opportunity Team ID | Opportunity ID | Team Member Email |
1000 | 1 | |
1001 | 1 | |
1003 | 1 | |
1004 | 2 | |
1005 | 2 | |
1006 | 3 |
Results
Alice | 400 |
Bob | 200 |
Jane | 300 |
Sam | 600 |
It is a one to many relationship between parent and child tables based on Opportunity ID.
Here is the Dax calculation I currently have that is working. I am using direct query and trying to improve performance. Is there a better way to calculate sum of amount when the current user is either the opportunity owner or on the opportunity team?
var CurrentUser = USERPRINCIPALNAME()
return
CALCULATE(SUM(' Opportunity '[Amount]),
FILTER(
' Opportunity ',
' Opportunity '[Opportunity Owner Email] = CurrentUser ||
CALCULATE(COUNTROWS(
FILTER(
' Opportunity Team ',
' Opportunity Team '[Team Member Email] = CurrentUser
)
)) > 0
)
)
Hi @jhills ,
Your measures seem pretty suitable In your scenario, We make some tiny change in it as following:
Measure 2 =
VAR CurrentUser =
USERPRINCIPALNAME ()
RETURN
CALCULATE (
SUM ( 'Opportunity'[Amount] ),
FILTER(
'Opportunity',
'Opportunity'[Opportunity Owner Email] = CurrentUser
|| CurrentUser in CALCULATETABLE(DISTINCT('Opportunity Team'[Team Member Email]))
)
)
You can compare the measure with previous one and find which one is faster in your scenario.
Best regards,
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
82 | |
66 | |
58 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |