Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

get last value from Date

Hello,   i am trying to get the last value from a date. This value should be use for the month before which are null.   The initial situation looks like that:     After a DAX-Function the ...
  • v-lili6-msft's avatar
    v-lili6-msft
    7 years ago

    HI, Anonymous

    You could try this formula to add a column as below:

    Value 2 = 
    VAR CurrentCar = 'Table'[Car]
    VAR CurrentDate = 'Table'[Month]
    VAR CurrentRegion = 'Table'[region]
    VAR LastDateWithValue =
        IF (
            ISBLANK ( 'Table'[Value] ) = FALSE (),
            'Table'[month],
            CALCULATE (
                MIN ( 'Table'[month] ),
                FILTER (
                    'Table',
                    'Table'[car] = EARLIER ( 'Table'[car] )
                        && 'Table'[region] = EARLIER ( 'Table'[region] )
                        &&'Table'[month]>=EARLIER('Table'[month])
                        && ISBLANK ( 'Table'[Value] ) = FALSE ()
                )
            )
        )
    RETURN
        VAR A =
            CALCULATE (
                LASTNONBLANK(  'Table'[Value], 'Table'[Value] ),
                FILTER (
                    'Table',
                    'Table'[Car] = CurrentCar
                        &&  'Table'[Month]  = LastDateWithValue
                        && 'Table'[region] = CurrentRegion
                )
            )
        RETURN
            IF ( ISBLANK ( 'Table'[Value] ), A, 'Table'[Value] )
    

    Result:

    Deeper testing

     

    Best Regards,

    Lin