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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
raybearz
Frequent Visitor

Date Diff Matching two different Columns in the Same Table

Hi all

 

I need to calculate the difference between two dates in the same column by matching a unique identifier from two columns of the same table. Please see below image

 

raybearz_0-1664293165206.png

 

I need to be able to match the transaction ID column with the REFNMBR Column by the same circled ID (197028) and the subtract the dates in the Transaction Date Column. 

 

Does anyone know of a solution?

 

Thanks,

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You could add the below as a calculated column

Date diff =
IF (
    NOT ( ISBLANK ( 'Table'[Ref Number] ) ),
    VAR RefNumber = 'Table'[Ref Number]
    VAR CurrentDate = 'Table'[Transaction date]
    VAR PrevDate =
        LOOKUPVALUE ( 'Table'[Transaction date], 'Table'[Transaction ID], RefNumber )
    RETURN
        DATEDIFF ( PrevDate, CurrentDate, DAY )
)

View solution in original post

4 REPLIES 4
johnt75
Super User
Super User

You could add the below as a calculated column

Date diff =
IF (
    NOT ( ISBLANK ( 'Table'[Ref Number] ) ),
    VAR RefNumber = 'Table'[Ref Number]
    VAR CurrentDate = 'Table'[Transaction date]
    VAR PrevDate =
        LOOKUPVALUE ( 'Table'[Transaction date], 'Table'[Transaction ID], RefNumber )
    RETURN
        DATEDIFF ( PrevDate, CurrentDate, DAY )
)

it worked. thank you so much!

 

Hi John

 

Seems like this will work, however, there can be multiple rows of the same Reference ID for each transaction ID

 

I am getting this message returned:

 

raybearz_0-1664295716921.png

 

Any way around this?

If there are multiple entries with the same transaction ID you'll need to decide which one is the correct one to use - earliest, most recent, some other criteria etc. Then you can you replace the LOOKUPVALUE with some variation on

SELECTCOLUMNS( CALCULATETABLE( TOPN( 1, 'Table', sort criteria), 
REMOVEFILTERS('Table'),
'Table'[Transaction ID] = RefNumber),
"@val", 'Table'[Transaction date])
)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors