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
ade_kurniawan
Frequent Visitor

Locate Previous Transaction Date & Place

Dear Friends,

 

Please help me, i want to locate previous transaction : date & location.

here is the data :

ID CUSTOMERTRANSACTION DATELOCATION
AB1231/1/2022B
AB1231/7/2022A
AC3441/4/2022B
AC3441/5/2022B
AC3441/18/2022B
AC3441/29/2022A
AF7891/4/2022B
AF7891/17/2022A
AF7891/19/2022B

 

here is output that i want :

ID Customerprevious transaction dateLocation Previous transaction
AB1231/1/2022B
AC3441/18/2022B
AF7891/17/2022A

 

I prefer to use DAX command, because i use live connection.

Link PBI File 

 

Thanks for help

1 ACCEPTED SOLUTION

4 REPLIES 4
ade_kurniawan
Frequent Visitor

Thanks for help @SpartaBI & @CNENFRNL but i have another problem :
my data is in different table & i cant use variable that hide in table : PBI separated table 

thanks

@ade_kurniawan hey, check this for my vesrion.
Is that what you need?
Transaction Customer v4.pbix


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1654159091969.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

SpartaBI
Community Champion
Community Champion

@ade_kurniawan create these measures:

 

Previous transaction date = 
VAR _current_date = MAX(Sheet1[TRANSACTION DATE])
VAR _current_id = SELECTEDVALUE(Sheet1[ID CUSTOMER])
RETURN
CALCULATE(
    MAX(Sheet1[TRANSACTION DATE]),
    REMOVEFILTERS(Sheet1),
    Sheet1[ID CUSTOMER] = _current_id,
    Sheet1[TRANSACTION DATE] < _current_date
)


Location of Previous transaction date = 
VAR _current_date = MAX(Sheet1[TRANSACTION DATE])
VAR _current_id = SELECTEDVALUE(Sheet1[ID CUSTOMER])
VAR _previous_transaction_date = 
CALCULATE(
    MAX(Sheet1[TRANSACTION DATE]),
    REMOVEFILTERS(Sheet1),
    Sheet1[ID CUSTOMER] = _current_id,
    Sheet1[TRANSACTION DATE] < _current_date
)
RETURN
CALCULATE(
    SELECTEDVALUE(Sheet1[LOCATION]),
    REMOVEFILTERS(Sheet1),
    Sheet1[ID CUSTOMER] = _current_id,
    Sheet1[TRANSACTION DATE] = _previous_transaction_date
)

 

Put them next to the ones you already have in the table.
You need to also put the current transaction data in the visual for it to work. Previous need to be previous to something:

SpartaBI_0-1654156411965.png

 

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

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.