Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

First date attribute seen within sequence

I have the following asset condition data   AssetID Date Condition A123 01/01/2013   2 A123 01/01/2014   2 A123 01/01/2015   3 A123 01/01/2016   3 A123 01/01/2017   4 ...
  • johnt75's avatar
    4 years ago
    Earliest Current Condition Date = 
    var currentAsset = SELECTEDVALUE('Table'[AssetID])
    var currentCondition = SELECTCOLUMNS( CALCULATETABLE( TOPN( 1,'Table', 'Table'[Date], DESC),'Table'[AssetID] = currentAsset),
    "@condition", 'Table'[Condition] )
    var prevConditionDate = CALCULATE( MAX('Table'[Date]), REMOVEFILTERS('Table'), 'Table'[AssetID] = currentAsset && 'Table'[Condition] <> currentCondition )
    var result = CALCULATE( MIN('Table'[Date]),REMOVEFILTERS('Table'),
    'Table'[AssetID] = currentAsset && 'Table'[Condition] = currentCondition && 'Table'[Date] > prevConditionDate )
    return result