Forum Discussion
raybearz
3 years agoFrequent 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 I need to be...
- 3 years ago
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 ) )
raybearz
3 years agoFrequent Visitor
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:
Any way around this?
johnt75
Super User
3 years agoIf 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])
)