Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rchung2
New Member

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
1 ACCEPTED SOLUTION
TomMartens
Super User
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"

 

image.png

Hopefully this is what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

2 REPLIES 2
TomMartens
Super User
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"

 

image.png

Hopefully this is what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi, Tom.

 

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

 

Thanks so much!!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.