Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Define new and existing customer?

I would like to define 2 sets of customers to identify number of product opens per year and the type of customer they are: Existing Customer Adds Product - these are customers who had an existing ac...
  • v-juanli-msft's avatar
    6 years ago

    Hi Anonymous 

    Create a new table,

    account table = DISTINCT(UNION(VALUES('Table'[Account Code]),VALUES('Table 2'[Account Code])))

    Add a calculated column

    final column =
    VAR account_date =
        CALCULATE (
            MAX ( 'Table'[Account Open Date] ),
            FILTER (
                'Table',
                'Table'[Account Code]
                    = EARLIER ( 'account table'[Account Code] )
            )
        )
    VAR product_date =
        CALCULATE (
            MAX ( 'Table 2'[Product Open Date] ),
            FILTER (
                'Table 2',
                'Table 2'[Account Code]
                    = EARLIER ( 'account table'[Account Code] )
            )
        )
    VAR year_diff =
        DATEDIFF (
            account_date,
            product_date,
            YEAR
        )
    VAR day_diff =
        DATEDIFF (
            account_date,
            product_date,
            DAY
        )
    RETURN
        IF (
            year_diff >= 1,
            "exsiting customer",
            IF (
                year_diff = 0
                    && day_diff <= 60,
                "new customer",
                "exsiting customer"
            )
        )
    

     

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.