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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.