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
zingiwng
Frequent Visitor

How do I find the latest date related to an id.

I have 2 tables and I am trying to find and display the latest contact date for each opportunity

 

The tables are linked with with ID 1 -> * Oppt_ID

 

Opportinities

ID              Name             Account Manger

1                oppt 1            John Doe

2                oppt 2            Jane Doe

 

Activites

ID           Oppt_ID         Note                             Latest Contact

1              1                    sent email                     12/26/2016

2              1                    made phone call           02/20/2017

3              1                    on site meeting            04/28/2017

4              2                    first meeting                 01/03/2017

5              2                    email sent                     05/01/2017

 

 

I was thinking I could create a new column with a simple yes or no and filter by that, but I'm not sure how to aproach this.

 

I've tried following queries below but the column is always yes.

 

column = if(RELATED(Opportunities[id]) = [oppt_id] && MAX([Latest Contact]), "yes", "no")
column = if(RELATED(Opportunities[id]) = [oppt_id] && LASTDATE(Activities[Latest Contact]), "yes", "no")

What can I do to find the Latest Contact for an opportunity?

 

Thanks

 

zingwing

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Column = CALCULATE(MAX([Latest Contact]),RELATEDTABLE(Activities))

In your Opportunities table create that column. Make sure Opportunities and Activities are related on ID in Opportunity and Oppt_ID in Activities.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Column = CALCULATE(MAX([Latest Contact]),RELATEDTABLE(Activities))

In your Opportunities table create that column. Make sure Opportunities and Activities are related on ID in Opportunity and Oppt_ID in Activities.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Awesome thanks @Greg_Deckler  that query does that the job.

 

However, I found one issue. If I add the notes field from activites to the table it will still will display every note realated. 

 

 

ID            Opportunity           Latest Contact            Note

1              opp1                        04/28/2017                  on site meeting

1              opp1                        04/28/2017                  made phone call

1              opp1                        04/28/2017                  sent email

 

 

Is there a way to show the correct note with the latest contact?

Perhaps create a measure for Notes like:

 

MeasureNote = VALUES([Note])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Nope, that won't work, let me see if I can figure it out.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.