Forum Discussion

CAPEconsulting's avatar
CAPEconsulting
Helper III
6 years ago
Solved

First and Last Purchase

I am trying to create a calculated column that marks a "First" and "Last" purchase of a customer by product where reason is not 2 (reason 1 was initiation in the store and reason 3 was final transfer...
  • CAPEconsulting's avatar
    CAPEconsulting
    6 years ago

    Actually, looks like I must have mistyped something somewhere, as my initial syntax works just fine - and will be perfect for large datasets too

    Status =
    VAR
    First = CALCULATE(MIN(O[Date]), ALLEXCEPT(O,O[CustID], O[Type]), FILTER(SUMMARIZE(O, O[Score], O[reason]), O[reason] = 1 && O[Score] <> 999))
    VAR
    Last = CALCULATE(MAX(O[Date]), ALLEXCEPT(O,O[CustID], O[Type]), FILTER(SUMMARIZE(O, O[Score], O[reason]), O[reason] = 3 && O[Score] <> 999))
    RETURN
    IF(O[Date] = First, "Pre", IF(O[Date] = Last, "Post", BLANK()))