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

View all the Fabric Data Days sessions on demand. View schedule

Reply
BryceJones
Frequent Visitor

A calculated column or custom column that compares two date columns output which date it is closest

Hello all,

 

I need to create either a calculated column in DAX or a custom column in PowerQuery that compare two date columns in two tables. The output is a column that has the value in the second table that is closest to the first table that is greater than the first table. I am unable to upload the file directly. However, this is the first table: 

BryceJones_0-1737556687151.png

Here is the second: 

BryceJones_1-1737556727116.png

And here is the desired output with the comparison being done on the Begin Date in the first table and the Date column in the second 

BryceJones_2-1737556806899.png

 

1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @BryceJones ,

You can achieve your goal by creating a new calculated column in first table with this DAX:

Closest Date = 
VAR CurrentBeginDate = 'FirstTable'[Begin Date]
RETURN
    MINX(
        FILTER(
            'SecondTable',
            'SecondTable'[Date] > CurrentBeginDate
        ),
        'SecondTable'[Date]
    )

 

Your output will look like this:

Bibiano_Geraldo_0-1737569854070.png

 

 

View solution in original post

4 REPLIES 4
Bibiano_Geraldo
Super User
Super User

Hi @BryceJones ,

You can achieve your goal by creating a new calculated column in first table with this DAX:

Closest Date = 
VAR CurrentBeginDate = 'FirstTable'[Begin Date]
RETURN
    MINX(
        FILTER(
            'SecondTable',
            'SecondTable'[Date] > CurrentBeginDate
        ),
        'SecondTable'[Date]
    )

 

Your output will look like this:

Bibiano_Geraldo_0-1737569854070.png

 

 

@Bibiano_Geraldo  

 

Thank you so much. This worked!

amitchandak
Super User
Super User

@BryceJones , A new column in Table 1

 

Maxx(filter(Table2, Table2[Date] >= Table1[Start Date] && Table2[Date] <= Table1[End Date]) , Table2[Date])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak ,

 

Thank you. To clarify Begin Date and Date are the only dates in my scenario that need this comparison performed on.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors