Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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:
| Athlete Name | Test Date | Test Result | Bodyweight Scan Date | Bodyweight in KG |
Athlete A | 1/1/2022 | 60 | 12/28/2021 | 80 |
| Athlete A | 2/1/2022 | 70 | 2/3/2022 | 78 |
| Athlete A | 3/1/2022 | 80 | 3/2/2022 | 79 |
Solved! Go to Solution.
Hi @drivas771994 ,
According to your description, you have two tables, SPARTA_SCANS2 and TESTS, I create a sample.
Test table:
SPARTA_SCANS2 table:
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.
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.
Hi @drivas771994 ,
According to your description, you have two tables, SPARTA_SCANS2 and TESTS, I create a sample.
Test table:
SPARTA_SCANS2 table:
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.
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.
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]
)
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 6 | |
| 5 |
| User | Count |
|---|---|
| 24 | |
| 21 | |
| 18 | |
| 14 | |
| 14 |