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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
drivas771994
Helper II
Helper II

How to pull most recent data based on a a data value from another table.

Hi,

I'm trying to pull data from one table based on the relationship to a date from another table. Here's the example.

 

I have two tables called tests and scans. In the test table i have test results that I want to compare against a bodyweight in my scans table. The issue is that they don't usually occur on the same day. So I have gotten my table to pull the closest date to which an athlete's bodyweight occurs in relation to the test but can't get the actual bodyweight. Here's my formula:

 
Most Recent Body Mass =
var dateweight=selectedvalue(SPARTA_SCANS2[Date])
return
calculate(min(TESTS[Date]), TESTS[Date]>=dateweight)
 
Below is a demo table of what I'm trying to get. The column in red is what I'm trying to get but can't
 
Athlete NameTest DateTest ResultBodyweight Scan DateBodyweight in KG

Athlete A

1/1/2022

6012/28/202180
Athlete A2/1/2022702/3/202278
Athlete A3/1/2022803/2/202279
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @drivas771994 ,

According to your description, you have two tables, SPARTA_SCANS2 and TESTS, I create a sample.

Test table:

vkalyjmsft_0-1654582786619.png

SPARTA_SCANS2 table:

vkalyjmsft_1-1654582805679.png

You want to get the Body weight of the latest Test Date which are greater than current Scan Date.

Here's my solution.

Most Recent Body Mass =
MAXX (
    FILTER (
        ALL ( 'TESTS' ),
        'TESTS'[Date]
            = MINX (
                FILTER ( ALL ( 'TESTS' ), 'TESTS'[Date] >= MAX ( 'SPARTA_SCANS2'[Date] ) ),
                'TESTS'[Date]
            )
    ),
    'TESTS'[Bodyweight]
)

Get the correct result.

vkalyjmsft_2-1654582829734.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @drivas771994 ,

According to your description, you have two tables, SPARTA_SCANS2 and TESTS, I create a sample.

Test table:

vkalyjmsft_0-1654582786619.png

SPARTA_SCANS2 table:

vkalyjmsft_1-1654582805679.png

You want to get the Body weight of the latest Test Date which are greater than current Scan Date.

Here's my solution.

Most Recent Body Mass =
MAXX (
    FILTER (
        ALL ( 'TESTS' ),
        'TESTS'[Date]
            = MINX (
                FILTER ( ALL ( 'TESTS' ), 'TESTS'[Date] >= MAX ( 'SPARTA_SCANS2'[Date] ) ),
                'TESTS'[Date]
            )
    ),
    'TESTS'[Bodyweight]
)

Get the correct result.

vkalyjmsft_2-1654582829734.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

johnt75
Super User
Super User

You could create a measure like

Most Recent Body Mass =
var currentAthlete = SELECTEDVALUE('Scans'[Athlete])
var currentDate = SELECTEDVALUE('Scans'[Date])
return SELECTCOLUMNS(
CALCULATETABLE( TOPN( 1, 'Tests', 'Tests'[Date]),
'Tests'[Athlete] = currentAthlete && 'Tests'[Date] <= currentDate),
"@val", 'Tests'[Body weight]
)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.