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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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

 

 

Is this post help you? Please consider to:
Accept as Solution!
Give a Kudo
Follow me on Linkedin: Bibiano_Geraldo_Mangue

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

 

 

Is this post help you? Please consider to:
Accept as Solution!
Give a Kudo
Follow me on Linkedin: Bibiano_Geraldo_Mangue

@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])

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
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.