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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
UserQuestions_
Regular 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
Impactful Individual
Impactful Individual

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
Impactful Individual
Impactful Individual

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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