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
Anonymous
Not applicable

join table but only most recent value

I need help. Can be DAX or M.

I have table1 with code and date (and more irrelevant columns).
I have table2 with the same code and date, but also a value that changes from time to time.

I need to insert a new column in table1, getting the value from table2, but only the values from the most recent date.

This new value on table2 from the most recent date might be higher or lower than the previous values.

 

On the example below, code A stays the same, code B goes higher from 4 to 16, but code C goes lower from 8 to 2.
It could change a lot of times, not only 2 times like this example.

See that the dates don´t match between tables. Table2 starts on Jan/01 but Table1 starts on Jan/10.

Dates and codes combined from Table1 are not distinct.

Dates and codes combined from Table2 are distinct.

 

recent value only.png

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

Try this DAX formula, please. 

Column =
VAR currentCode = [code]
VAR currentDate = [date]
VAR maxDateOfTable2 =
    CALCULATE (
        MAX ( 'Table2'[date] ),
        'Table2'[date] <= currentDate,
        Table2[code] = currentCode
    )
RETURN
    LOOKUPVALUE (
        Table2[value],
        Table2[code], currentCode,
        Table2[date], maxDateOfTable2
    )

join_table_but_only_most_recent_value

 

Best Regards,

Dale

Community Support Team _ Dale
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

I found a way, but I don´t think it is a nice solution.

I got my table1 and duplicated it.

Remove all columns but code and date.

Then, I append it below table2, like this:

 

recent value only2.png

 

This is the new table2.

Then I created a new field which is: code+yyyy+MM+dd.

Order it ascending.

Use the Fill Down option from the Transform ribbon.

vòila!

Now I have a table like this below. Numbers in red are the Fill Down result.

 

recent value only3.png

Hi @Anonymous,

 

Try this DAX formula, please. 

Column =
VAR currentCode = [code]
VAR currentDate = [date]
VAR maxDateOfTable2 =
    CALCULATE (
        MAX ( 'Table2'[date] ),
        'Table2'[date] <= currentDate,
        Table2[code] = currentCode
    )
RETURN
    LOOKUPVALUE (
        Table2[value],
        Table2[code], currentCode,
        Table2[date], maxDateOfTable2
    )

join_table_but_only_most_recent_value

 

Best Regards,

Dale

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

yeah! it worked! thanks a lot!

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.