Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Calculated column that compares multiple columns and returns latest date

Hi all, 

 

I have a data set that is set-up with multiple records that had various changes and addendums to them (changes to rates, duration, etc) they are all identified by a CTR No. though. 

 

I wondered if there was a way that I could use DAX to draw out the various CTR No. and only return the latest date in each deadline column (currently I get multiple rows as opposed to just the final 'end' date). 

 

The data looks roughtly like this:

 

StartDeadlineCTR No Head CTR No
01/01/202031/08/20215986Date change5702
01/01/202030/06/20215875Rates error5702
01/01/202031/03/20215702  

 

How do I go about just getting one result back for dates on 5702 that is 31/08/2021? 

 

Thanks

 

 

  • Anonymous , You can get the latest value on CTR No

     

    measure

    latest price =
    VAR __id = MAX ('Table'[CTR No] )
    VAR __date = CALCULATE ( MAX('Table'[Deadline] ), ALLSELECTED ('Table' ), 'Table'[CTR No] = __id )
    CALCULATE ( MAX ('Table'[Head CTR No] ), VALUES ('Table'[CTR No] ),'Table'[CTR No] = __id,'Table'[Deadline] = __date )

     

2 Replies

  • Anonymous , You can get the latest value on CTR No

     

    measure

    latest price =
    VAR __id = MAX ('Table'[CTR No] )
    VAR __date = CALCULATE ( MAX('Table'[Deadline] ), ALLSELECTED ('Table' ), 'Table'[CTR No] = __id )
    CALCULATE ( MAX ('Table'[Head CTR No] ), VALUES ('Table'[CTR No] ),'Table'[CTR No] = __id,'Table'[Deadline] = __date )

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks - so I just use that as a calculated column, or do I need to split it into separate measures?