Forum Discussion

RSSILVA_22's avatar
RSSILVA_22
Helper I
3 years ago
Solved

remaining column to return previous payment amount

Good afternoon.
I need help creating a calculated column that returns the customer's previous payment amount.

 

example. Line 1 of the image below.

For the customer abc123, the value of the first must bring in a new column the value of 40 (referring to the payment made on 2021-10-05)

if there is no previous payment show empty

 

Link download do pbix.

https://drive.google.com/file/d/1Sw5hZGNfZyK5_xz8C4yR2yQiwGun3z66/view?usp=sharing

 

Thanks if anyone can take the time to hel

  • Hi RSSILVA_22 

    if you're looking for a calculated column then please try

    Previous Payment =
    VAR CurrentDate = 'Table'[payment date]
    VAR CurrentTable =
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[cod_client] ) )
    VAR TableBefore =
    FILTER ( CurrentTable, 'Table'[payment date] < CurrentDate )
    VAR PreviousRecord =
    TOPN ( 1, TableBefore, 'Table'[payment date] )
    RETURN
    MAXX ( PreviousRecord, 'Table'[value] )

4 Replies

  • Use the following code...

     

    Previous Value Total = VAR currentDate = SELECTEDVALUE('pratic'[payment date])
    VAR previousDate = MAXX(FILTER(ALL('pratic'),pratic[payment date]<currentDate && 'pratic'[cod_client]=MAX('pratic'[cod_client])),'pratic'[payment date])
    RETURN 
    IF(ISINSCOPE('pratic'[cod_client]),
    CALCULATE([Value Total],FILTER(ALLSELECTED('pratic'),previousDate='pratic'[payment date]))
    ,[Value Total])

     

     

    You could also use the following to check if PaymentDate is being used and default the value to Total if not...

    Previous Value Total = VAR currentDate = SELECTEDVALUE('pratic'[payment date])
    VAR previousDate = MAXX(FILTER(ALL('pratic'),pratic[payment date]<currentDate && 'pratic'[cod_client]=MAX('pratic'[cod_client])),'pratic'[payment date])
    RETURN 
    SWITCH(TRUE()
    ,AND(ISINSCOPE('pratic'[cod_client]),(ISINSCOPE(pratic[payment date]))), CALCULATE([Value Total],FILTER(ALLSELECTED('pratic'),previousDate='pratic'[payment date]))
    ,AND(ISINSCOPE('pratic'[cod_client]),NOT(ISINSCOPE(pratic[payment date]))),[Value Total]
    ,[Value Total])

     

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi RSSILVA_22 

    if you're looking for a calculated column then please try

    Previous Payment =
    VAR CurrentDate = 'Table'[payment date]
    VAR CurrentTable =
    CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[cod_client] ) )
    VAR TableBefore =
    FILTER ( CurrentTable, 'Table'[payment date] < CurrentDate )
    VAR PreviousRecord =
    TOPN ( 1, TableBefore, 'Table'[payment date] )
    RETURN
    MAXX ( PreviousRecord, 'Table'[value] )