Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
RSSILVA_22
Helper I
Helper I

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)

RSSILVA_22_0-1679503420687.png

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

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

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] )

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

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] )

very good
thanks.

BrianConnelly
Resolver III
Resolver III

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])

 

 

BrianConnelly_0-1679505350778.png

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])

 

Thanks for the feedback.
Very good instructions.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors