Forum Discussion
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 A | ITEM A | 1/1/2018 | 1 | FIRST PURCHASE |
| CUSTOMER A | ITEM A | 1/2/2018 | 2 | RE PURCHASE |
| CUSTOMER A | ITEM A | 1/3/2018 | 3 | RE PURCHASE |
| CUSTOMER A | ITEM A | 1/4/2018 | 4 | RE PURCHASE |
| CUSTOMER A | ITEM B | 1/5/2018 | 5 | FIRST PURCHASE |
| CUSTOMER A | ITEM B | 1/6/2018 | 6 | RE PURCHASE |
| CUSTOMER A | ITEM B | 1/7/2018 | 7 | RE PURCHASE |
| CUSTOMER A | ITEM B | 1/8/2018 | 8 | RE PURCHASE |
| CUSTOMER A | ITEM B | 1/9/2018 | 9 | RE PURCHASE |
| CUSTOMER B | ITEM A | 1/10/2018 | 10 | FIRST PURCHASE |
| CUSTOMER B | ITEM A | 1/11/2018 | 11 | RE PURCHASE |
| CUSTOMER B | ITEM A | 1/12/2018 | 12 | RE PURCHASE |
| CUSTOMER B | ITEM A | 1/13/2018 | 13 | RE PURCHASE |
| CUSTOMER B | ITEM B | 1/14/2018 | 14 | FIRST PURCHASE |
| CUSTOMER B | ITEM B | 1/15/2018 | 15 | RE PURCHASE |
| CUSTOMER B | ITEM B | 1/16/2018 | 16 | RE PURCHASE |
| CUSTOMER B | ITEM B | 1/17/2018 | 17 | RE PURCHASE |
| CUSTOMER B | ITEM B | 1/18/2018 | 18 | RE 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
- TomMartens
Super User
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
- rchung2New Member
Hi, Tom.
This is great. Everything works as how it supposed to do.
Thanks so much!!!