cancel
Showing results for 
Search instead for 
Did you mean: 
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
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors