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

Get the most recent value from another table with measures

Hello experts,

 

I ran into this question and hope to get your advice on it.

 

I have two tables: 

Table 1: Item, Date

Table 2: Item, Date, Value

 

I want to be able to find the most recent date from Table2 that before Table1 date, and also get the value.

I have been tried with Calculated Columns but didn't look right: 

 

Column =
CALCULATE(
    MAX(T2[Time]),
    FILTER(T2,
    T2[Time] <= T1[Time]))
 
Column 2 =
LOOKUPVALUE(T2[Value],T2[Time],T1[Column])

 

XR043_0-1676279321364.png

I tried measures but but didn't work well.

 

Measure =
VAR _maxdate = MAX(T1[Time])
VAR _maxitem = MAX(T1[Item])
RETURN
CALCULATE(
    MAX(T2[Value]),FILTER(ALL(T2),T2[Time]<=_maxdate&&T2[Item] =_maxitem)
    )
 
My question is:
How to do this by measures? Otherwise how to do it with calcualted columns?
 
Many thanks
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@XR043 , new column in table 1

 

MAX(Filter(T2,T2[Time] =t1[Time] &&T2[Item] =T1[Item]), T2[Value])

 

refer 4 ways (related, relatedtable, lookupvalue, sumx/minx/maxx with filter) to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@XR043 , new column in table 1

 

MAX(Filter(T2,T2[Time] =t1[Time] &&T2[Item] =T1[Item]), T2[Value])

 

refer 4 ways (related, relatedtable, lookupvalue, sumx/minx/maxx with filter) to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

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.