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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
alya1
Helper V
Helper V

get value from another table based on 2 conditions, matching ID b/w tables and max date from org

Hellow I have 2 tables as below:
table 1:

ID DateUnit
11/1/2023 1
11/2/2023 1
11/3/2023 2
25/6/2023 5
25/7/2023 4

table 2:

ID
1
2

 

How do I add a new column to table 2 for Unit based on max Date from table 1 and matching ID?
goal table 2: 

ID Unit
12
24

 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,@alya1

Thanks for letting us know your user experience. According to your case description, I do understand how frustrated you are now.

Regarding the issue you raised, my solution is as follows:

1.I noticed that you are using calculated columns, while the code I gave is for measure. The way I display it is as follows.

vlinyulumsft_2-1716541509450.png

And there is a relationship between my table:

vlinyulumsft_3-1716541533341.png

2.Of course, if you want to use calculation columns, here is my calculation column:

 

 

unit Column = 
var maxcatime=CALCULATE(MAX('Table1'[Date]),FILTER('Table1','Table1'[id]=EARLIER('Table'[id])))
RETURN CALCULATE(MAX('Table1'[Unit]),FILTER(ALLSELECTED('Table1'),'Table1'[Date]=maxcatime))

 

 

3.Here is the final result, hopefully to meet your needs:

vlinyulumsft_4-1716541577595.png

Also, my pbix file is attached to this reply, you can extract it according to your needs.

If you need other help from my side, please let me know.

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi,@alya1 

Regarding the issue you raised, my solution is as follows:

1. Below are the measure I've created for your needs:

 

 

unit = 
var maxcatime=CALCULATE(MAX('Table1'[Date]),FILTER(ALLSELECTED('Table1'),'Table1'[id]=MAX('Table1'[id])))
RETURN CALCULATE(MAX('Table1'[Unit]),FILTER(ALLSELECTED('Table1'),'Table1'[Date]=maxcatime))

 

 

2.Here's my final result, which I hope meets your requirements.

vlinyulumsft_0-1716340654441.png

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Leroy, thank you for your reply, I think it's on the right track! But would you mind double checking the DAX you posted please? I did it on my own and got "4" for both IDs:

alya1_2-1716392654560.png

 

alya1_1-1716392633489.png

I also realized the Unit column is text with some being R7 or E1 instead of just 7 or 1. Would that change the DAX?

Anonymous
Not applicable

Hi,@alya1

Thanks for letting us know your user experience. According to your case description, I do understand how frustrated you are now.

Regarding the issue you raised, my solution is as follows:

1.I noticed that you are using calculated columns, while the code I gave is for measure. The way I display it is as follows.

vlinyulumsft_2-1716541509450.png

And there is a relationship between my table:

vlinyulumsft_3-1716541533341.png

2.Of course, if you want to use calculation columns, here is my calculation column:

 

 

unit Column = 
var maxcatime=CALCULATE(MAX('Table1'[Date]),FILTER('Table1','Table1'[id]=EARLIER('Table'[id])))
RETURN CALCULATE(MAX('Table1'[Unit]),FILTER(ALLSELECTED('Table1'),'Table1'[Date]=maxcatime))

 

 

3.Here is the final result, hopefully to meet your needs:

vlinyulumsft_4-1716541577595.png

Also, my pbix file is attached to this reply, you can extract it according to your needs.

If you need other help from my side, please let me know.

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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