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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
UserQuestions_
Frequent Visitor

Need to identify customer type by customer ID and Order ID

I have a large dataset with Sales transactions, Customer ID, Order ID and products purchased with time & date. I am needing to classify customers on if they are returning, unknown or new leveraging customer ID and distinct count of order ID. 


If a customer ID = 0, they are unknown

If unique customer ID = 1 unique order ID, they are new

If unique customer ID > 1 unique order ID, they are returning. 

 

My sales table  is set up:

Customer IDOrder IDProduct IDNet SalesQtyPOS Location
73571112345151online
735711123462101store 1
73571112347351store 1
00897211415151online
018791151 online

 

I have tried a calculated column & measure but keep receiving syntax errors. Thank you for your assistance! 

1 ACCEPTED SOLUTION
SamsonTruong
Super User
Super User

Hi @UserQuestions_ ,

Please try the following DAX for a calculated column and let me know if this achieves your desired result:

Customer Type = 
VAR CurrentCustomer = 'Sales'[Customer ID]
VAR DistinctOrderCount = 
    CALCULATE(
        DISTINCTCOUNT('Sales'[Order ID]),
        ALLEXCEPT('Sales', 'Sales'[Customer ID])
    )
RETURN
    SWITCH(
        TRUE(),
        CurrentCustomer = 0, "Unknown",
        DistinctOrderCount = 1, "New",
        DistinctOrderCount > 1, "Returning"
    )

 

If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

Thanks,

Samson

 

Connect with me on LinkedIn

Check out my Blog

Going to the European Microsoft Fabric Community Conference? Check out my Session

View solution in original post

3 REPLIES 3
SamsonTruong
Super User
Super User

Hi @UserQuestions_ ,

Please try the following DAX for a calculated column and let me know if this achieves your desired result:

Customer Type = 
VAR CurrentCustomer = 'Sales'[Customer ID]
VAR DistinctOrderCount = 
    CALCULATE(
        DISTINCTCOUNT('Sales'[Order ID]),
        ALLEXCEPT('Sales', 'Sales'[Customer ID])
    )
RETURN
    SWITCH(
        TRUE(),
        CurrentCustomer = 0, "Unknown",
        DistinctOrderCount = 1, "New",
        DistinctOrderCount > 1, "Returning"
    )

 

If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

Thanks,

Samson

 

Connect with me on LinkedIn

Check out my Blog

Going to the European Microsoft Fabric Community Conference? Check out my Session

Thank you so much this worked perfectly! 

Awesome, glad to hear it worked!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.