Forum Discussion

rchung2's avatar
rchung2
New Member
7 years ago
Solved

Questions regarding first/new customer

Hi,

 

I'm trying to make a calculated column that can distinguish between first/re purchase of each item per each customer.

 

I need the last column!

 

Please help!!

 

Thanks so much!!

 

CUSTOMERITEMPURCHASE DATEQTYCOLUMN

CUSTOMER AITEM A1/1/20181FIRST PURCHASE
CUSTOMER AITEM A1/2/20182RE PURCHASE
CUSTOMER AITEM A1/3/20183RE PURCHASE
CUSTOMER AITEM A1/4/20184RE PURCHASE
CUSTOMER AITEM B1/5/20185FIRST PURCHASE
CUSTOMER AITEM B1/6/20186RE PURCHASE
CUSTOMER AITEM B1/7/20187RE PURCHASE
CUSTOMER AITEM B1/8/20188RE PURCHASE
CUSTOMER AITEM B1/9/20189RE PURCHASE
CUSTOMER BITEM A1/10/201810FIRST PURCHASE
CUSTOMER BITEM A1/11/201811RE PURCHASE
CUSTOMER BITEM A1/12/201812RE PURCHASE
CUSTOMER BITEM A1/13/201813RE PURCHASE
CUSTOMER BITEM B1/14/201814FIRST PURCHASE
CUSTOMER BITEM B1/15/201815RE PURCHASE
CUSTOMER BITEM B1/16/201816RE PURCHASE
CUSTOMER BITEM B1/17/201817RE PURCHASE
CUSTOMER BITEM B1/18/201818RE PURCHASE
  • Hey,

    I guess this DAX statement used with a calculated column creates what you are looking for:

     

    result = 
    var currentCustomer = 'Table1'[Customer]
    var currentItem = 'Table1'[Item]
    var minDate = 
        CALCULATE(
            MIN('Table1'[Purchase Date])
            ,ALL(Table1)
            ,'Table1'[Customer] = currentCustomer
            ,'Table1'[Item] = currentItem
        )
        return
        IF(
            AND(
                AND('Table1'[Customer] = currentCustomer, 'Table1'[Item] = currentItem)
                ,'Table1'[Purchase Date] = minDate
            )
            ,"First Purchase"
            ,"Re Purchase"
        )

    At least the new column "result" contains the same values of the column COLUMN from the sample data you provided, please note that I renamed the column from the test data to "TestResult"

     

    Hopefully this is what you are looking for.

     

    Regards,

    Tom

2 Replies

  • Hey,

    I guess this DAX statement used with a calculated column creates what you are looking for:

     

    result = 
    var currentCustomer = 'Table1'[Customer]
    var currentItem = 'Table1'[Item]
    var minDate = 
        CALCULATE(
            MIN('Table1'[Purchase Date])
            ,ALL(Table1)
            ,'Table1'[Customer] = currentCustomer
            ,'Table1'[Item] = currentItem
        )
        return
        IF(
            AND(
                AND('Table1'[Customer] = currentCustomer, 'Table1'[Item] = currentItem)
                ,'Table1'[Purchase Date] = minDate
            )
            ,"First Purchase"
            ,"Re Purchase"
        )

    At least the new column "result" contains the same values of the column COLUMN from the sample data you provided, please note that I renamed the column from the test data to "TestResult"

     

    Hopefully this is what you are looking for.

     

    Regards,

    Tom

    • rchung2's avatar
      rchung2
      New Member

      Hi, Tom.

       

      This is great. Everything works as how it supposed to do. 

       

      Thanks so much!!!