Forum Discussion

Ar_Sh's avatar
Ar_Sh
Icon for Advocate II rankAdvocate II
9 months ago
Solved

how to flg first purchase

I am cleaning up a customer transaction report. Each customer has multiple purchases and the table has CustomerID, Date, and Amount. I need a measure that marks only the first purchase for every customer as 1 and all others as 0. Basically, I want to identify the first transaction using DAX. What is the best way to handle this?

  • To flag the first purchase per customer in DAX, create a calculated column like this:

     
    FirstPurchaseFlag = IF ( Sales[Date] = CALCULATE ( MIN(Sales[Date]), FILTER(Sales, Sales[CustomerID] = EARLIER(Sales[CustomerID])) ), 1, 0 )

    This marks the earliest purchase date per customer as 1, others as 0. Use this to identify first transactions easily.

1 Reply

  • To flag the first purchase per customer in DAX, create a calculated column like this:

     
    FirstPurchaseFlag = IF ( Sales[Date] = CALCULATE ( MIN(Sales[Date]), FILTER(Sales, Sales[CustomerID] = EARLIER(Sales[CustomerID])) ), 1, 0 )

    This marks the earliest purchase date per customer as 1, others as 0. Use this to identify first transactions easily.