Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
jhills
Advocate II
Advocate II

Best way to write a measure summing an amount from a parent table filtering on column in child?

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

Alice@company.com

2

200

Bob@company.com

3

300

Alice@company.com

 

Opportunity Team:

Opportunity Team ID

Opportunity ID

Team Member Email

1000

1

Alice@company.com

1001

1

Sam@company.com

1003

1

Jane@company.com

1004

2

Sam@company.com

1005

2

Jane@company.com

1006

3

Sam@company.com

 

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

   )

)

2 REPLIES 2
v-lid-msft
Community Support
Community Support

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,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks @v-lid-msft I will give it a try.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.