Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Previous row value

Hi there,

I need to get previous row value (OFFER_TYPE) and need help. I tried DAX but its only giving me partial result.
The resulted values should be previous rows taken from column "OFFER_TYPE", as marked in blue in column "previous value".

 

INDEXPOD_PDR CODEDATEOFFER_TYPEPREEVIOUS VALUE

1

16666

01/01/21NEG 
21666601/02/21NEGNEG
31666601/03/21SEMINEGNEG
41666601/04/21SEMINEGSEMINEG
51666601/05/21SEMINEGSEMINEG

 

My DAX formula:

_getResult =
var _currentIndex=MAX(cb_attiva[INDEX])
var off_ = cb_attiva[OFFER_TYPE]
var final = CALCULATE( off_, FILTER(ALL(cb_attiva),cb_attiva[Indice]=_currentIndex-1))
return
final
 
 

I will appreciate your help.

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    Please try add a new column by below dax formula:

     

    Pre_Offer_type =
    VAR cur_index = 'Table'[INDEX]
    VAR pre_index = cur_index - 1
    VAR pre_value =
        CALCULATE (
            MAX ( 'Table'[OFFER_TYPE] ),
            FILTER ( 'Table', 'Table'[INDEX] = pre_index )
        )
    RETURN
        pre_value
    

     

     

    Best regards,
    Community Support Team_ Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Please try add a new column by below dax formula:

     

    Pre_Offer_type =
    VAR cur_index = 'Table'[INDEX]
    VAR pre_index = cur_index - 1
    VAR pre_value =
        CALCULATE (
            MAX ( 'Table'[OFFER_TYPE] ),
            FILTER ( 'Table', 'Table'[INDEX] = pre_index )
        )
    RETURN
        pre_value
    

     

     

    Best regards,
    Community Support Team_ Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.