Forum Discussion

kcantor's avatar
kcantor
Icon for Community Champion rankCommunity Champion
10 years ago
Solved

DAX Question - Customers who purchase again after a return.

I have a calculation I would like to build from two fact tables. I have a table that lists returns made and a table that lists purchases made. We can call them returns and sales for simplicity. My lo...
  • Greg_Deckler's avatar
    10 years ago

    Likely more elegant solutions than this, but you could create a calculated column:

     

    SaleAfterReturn = IF(MAXX(FILTER(sales,sales[Customer]=customers[customer]),sales[Date])>MAXX(FILTER(returns,returns[Customer]=customers[customer]),returns[Date]),1,0)

    And then a measure:

     

    % Customers After Return = COUNTX(FILTER(customers,customers[SaleAfterReturn]=1),customers[SaleAfterReturn])/COUNT(customers[SaleAfterReturn])

     

     

    I did this with a customer table:

     

    customers table

    customer

    1

    2

    3

     

    and a sales and returns table with Date and Customer. returns and sales and both related to the customers table.