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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Daretoexplore
Frequent Visitor

Most recent entry for a person

Hi all

 

I have some data which is customer and transaction based, like this.

 

CustID.         TransactionDate.         Amt

12345.          1/12/24.                      £32.45

12678.          1/12/24.                      £45.58

12345.          5/12/24.                      £24.62

 

(Just based on an example)

 

I'm looking to create a column which contains a '1' when it identifies the most recent transaction for each customer, son in the example above, it would have a column which would read 0 for the first row and 1 for the next 2.

 

Does anyone have any idea how to achieve this?

 

Many thanks.

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You could create a column like

Is Latest Date =
VAR LatestDate =
    CALCULATE (
        MAX ( 'Table'[Transaction Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Customer ID] )
    )
VAR Result =
    IF ( LatestDate = 'Table'[Transaction Date], 1 )
RETURN
    Result

View solution in original post

4 REPLIES 4
Bibiano_Geraldo
Memorable Member
Memorable Member

Hi, @Daretoexplore ,

To create a column that identifies the most recent transaction for each customer, you can use the following DAX formula in Power BI:

RecentTransaction = 
VAR LatestTransactionDate = 
    CALCULATE(
        MAX('Table'[Transactiondate]),
        ALLEXCEPT('Table', 'Table'[CustId.])
    )
RETURN
    IF('Table'[Transactiondate] = LatestTransactionDate, 1, 0)

 

Now your table should look like this:

Bibiano_Geraldo_0-1731585861113.png

 

If this reply help you, please accept as solution and give a Kudo.

 

Thank You.

I hope this helps! 
If you found this answer helpful:
✔️ Mark it as the solution to help others find it faster.
 Give it a like to show your appreciation!

Thank you for contributing to our amazing Power BI community! 
Kedar_Pande
Resident Rockstar
Resident Rockstar

@Daretoexplore 

 Create a New Calculated Column

IsMostRecentTransaction = 
VAR LatestDate =
CALCULATE(
MAX('YourTable'[TransactionDate]),
ALLEXCEPT('YourTable', 'YourTable'[CustID])
)
RETURN
IF('YourTable'[TransactionDate] = LatestDate, 1, 0)

You should see a 1 for the most recent transactions for each customer and a 0 for others.

 

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

johnt75
Super User
Super User

You could create a column like

Is Latest Date =
VAR LatestDate =
    CALCULATE (
        MAX ( 'Table'[Transaction Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Customer ID] )
    )
VAR Result =
    IF ( LatestDate = 'Table'[Transaction Date], 1 )
RETURN
    Result
FreemanZ
Super User
Super User

hi @Daretoexplore ,

 

try like:

column =

VAR _firstdate

MAXX(

    FILTER(

        data,

        data[CustID]=EARLIER(data[CustID])

    ),

    data[date]

)

RETURN

IF([date]=_firstdate, 1, 0)

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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