Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Trying to make a row-based measure

Hi there, I'm trying to make a measure that does the following: Gives a "Yes" value to rows of the most recent engine exchange per truck. I've currently written a measure that only gives ...
  • v-alq-msft's avatar
    v-alq-msft
    6 years ago

    Hi, Anonymous 

     

    You may try the following measure in SSAS.

    Cumulative Age = 
    var _date = SELECTEDVALUE(Table1[Date])
    var _equipmentid = SELECTEDVALUE(Table1[Equipment ID])
    var _eventid = SELECTEDVALUE(Table1[Event ID])
    var _maxdate = 
    CALCULATE(
                MAX(Table1[Date]),
                FILTER(
                    ALL(Table1),
                    Table1[Equipment ID] = _equipmentid
                )
            )
    return
    IF(
        _eventid = "ENGINE EXCHANGE",
        0,
        IF(
            _date = _maxdate
            ,
            SELECTEDVALUE(Table1[Hour Reading])-
            CALCULATE(
                SUM(Table1[Hour Reading]),
                FILTER(
                    ALL(Table1),
                    Table1[Equipment ID] = _equipmentid&&
                    Table1[Event ID] = "ENGINE EXCHANGE"
                )
            ),
            SELECTEDVALUE(Table1[Hour Reading])
        )
    )
    Cumulative Cost = 
    var _date = SELECTEDVALUE(Table1[Date])
    var _equipmentid = SELECTEDVALUE(Table1[Equipment ID])
    var _eventid = SELECTEDVALUE(Table1[Event ID])
    var _lastdate = 
    CALCULATE(
        MAX(Table1[Date]),
        FILTER(
            ALL(Table1),
            Table1[Equipment ID] = _equipmentid&&
            Table1[Event ID] = "ENGINE EXCHANGE"&&
            Table1[Date]<_date
        )
    )
    return
    IF(
        _eventid = "ENGINE EXCHANGE",
        SELECTEDVALUE(Table1[Cost]),
        CALCULATE(
            SUM(Table1[Cost]),
            FILTER(
                ALL(Table1),
                Table1[Equipment ID] = _equipmentid&&
                Table1[Date]>=_lastdate&&
                Table1[Date]<=_date
            )
        )
    )

     

    Result:

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.