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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Cadams
Microsoft Employee
Microsoft Employee

Return Primary Partner based on 2 parameters (Date + ID)

Hi all,

 

I've been trying to figure this out for days now without any luck. I get close, but not the exact answer.

Here's the example data:

 

Cadams_1-1719929257989.png

 

What I'm looking to do is find the primary partner (output in table 1) who has created the latest (by created date) lead against the correct opportunity ID (table 2).

So for example, out of the 5 leads against opportunity ID "123" in table 2, Walmart is the latest lead to have been created and therefore, the "primary partner" field in table 1 is populated with Walmart.

I've tried using various formulas to get to the answer, e.g.:

 

CALCULATE(MAX([Partner Name]),FILTER(Table1 [opportunity ID] = table 2 [opportunity ID && max(table 2 created date)))

Or 

MAXX(FILTER(Table 2,MAX(table 2[Created Date]) && Table 1[Opportunity ID]=table 2 [opportunity ID),table 2 [partner name])

When I change the output from partner name to created date, it provides the correct date, which is the latest created lead, but when I change it back to partner name, it doesn't return the correct partner name.
 
Any help would be greatly appreciated. Please let me know if you need any additional context.
 
Thanks!

 



1 ACCEPTED SOLUTION
Irwan
Super User
Super User

Hello @Cadams ,

 

please check if this accomodate your need.

Irwan_0-1719966416727.png

 

Primary Partner =
var _MaxDate =
MAXX(
    FILTER(
        'Table 2',
        'Table 1'[Opportunity ID]='Table 2'[Opportunity ID]&&
        MAX('Table 2'[Created Date])
    ),
    'Table 2'[Created Date]
)
Return
MAXX(
    FILTER(
        'Table 2',
        'Table 2'[Created Date]=_MaxDate&&
        'Table 1'[Opportunity ID]='Table 2'[Opportunity ID]
    ),
    'Table 2'[Partner Name]
)

 

1. your maxx looks good, however the expression of maxx can be changed into date that returned a correct date as you mentioned above.

2. do maxx again with the date that previously calculated (which already return as accurate value) and matching opportunity ID. If you dont want to use maxx again, you can use CALCULATE as replacement.

 
Primary Partner =
var _MaxDate =
MAXX(
    FILTER(
        'Table 2',
        'Table 1'[Opportunity ID]='Table 2'[Opportunity ID]&&
        MAX('Table 2'[Created Date])
    ),
    'Table 2'[Created Date]
)
Return
CALCULATE(
    MAX('Table 2'[Partner Name]),
    FILTER(
        'Table 2',
        'Table 2'[Created Date]=_MaxDate&&
        'Table 1'[Opportunity ID]='Table 2'[Opportunity ID]
    )
)

 

And yes, if expression in first maxx is put directly into partner name, it would return into inaccurate value (from my experience, it because your data has skip date which is no 01/01/2024). However, since this is from my experience, my reason might be wrong.

 

Hope this will help you.

Thank you.

View solution in original post

3 REPLIES 3
Cadams
Microsoft Employee
Microsoft Employee

@Irwan , thank you so much. I've spent hours and hours trying to figure all combinations out, going through so many different forums and you got it in one!

Massive massive thank you!

Hello @Cadams 

 

Glad to be a help.

 

Thank you.

Irwan
Super User
Super User

Hello @Cadams ,

 

please check if this accomodate your need.

Irwan_0-1719966416727.png

 

Primary Partner =
var _MaxDate =
MAXX(
    FILTER(
        'Table 2',
        'Table 1'[Opportunity ID]='Table 2'[Opportunity ID]&&
        MAX('Table 2'[Created Date])
    ),
    'Table 2'[Created Date]
)
Return
MAXX(
    FILTER(
        'Table 2',
        'Table 2'[Created Date]=_MaxDate&&
        'Table 1'[Opportunity ID]='Table 2'[Opportunity ID]
    ),
    'Table 2'[Partner Name]
)

 

1. your maxx looks good, however the expression of maxx can be changed into date that returned a correct date as you mentioned above.

2. do maxx again with the date that previously calculated (which already return as accurate value) and matching opportunity ID. If you dont want to use maxx again, you can use CALCULATE as replacement.

 
Primary Partner =
var _MaxDate =
MAXX(
    FILTER(
        'Table 2',
        'Table 1'[Opportunity ID]='Table 2'[Opportunity ID]&&
        MAX('Table 2'[Created Date])
    ),
    'Table 2'[Created Date]
)
Return
CALCULATE(
    MAX('Table 2'[Partner Name]),
    FILTER(
        'Table 2',
        'Table 2'[Created Date]=_MaxDate&&
        'Table 1'[Opportunity ID]='Table 2'[Opportunity ID]
    )
)

 

And yes, if expression in first maxx is put directly into partner name, it would return into inaccurate value (from my experience, it because your data has skip date which is no 01/01/2024). However, since this is from my experience, my reason might be wrong.

 

Hope this will help you.

Thank you.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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