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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
user5341567
Frequent Visitor

Flagging customers as 'return' if they have more than one order

Hi all,

 

I have a table with one or more order_ids per customer_id, and I'm trying to flag customers who have more than one order_id as 'return' customers.

 

As an example below: I have customer_id and order_id, but I'm trying to populate customer_type.

 

order_ids 001, 002, 003, 004, and 005 have multiple records of the same customer_id, so I wish to flag that customer as 'Return'. order_id 006 only has one customer_id in the table, so I wish to flag that customer as 'New', etc.

 

user5341567_2-1741900994787.png

 

 

 

Has anyone tried to do this?

 

I tried to first count the number of orders per customer, then use another field to say 'if # of orders > 1 then return else new', but my formula returns 1. All of the solutions I have tried gives me 1.

 

Here's one of the formulas I tried:

 

# of orders =
CALCULATE (
    DISTINCTCOUNT ( Fact_orders[order_id] ),
    FILTER (
        ALL ( Fact_orders ),
        [customer_id] = MAX ( Fact_orders[customer_id] )
    )
)
 
Any insight would be greatly appreciated!
1 ACCEPTED SOLUTION
Deku
Continued Contributor
Continued Contributor

Deku_0-1741902829484.png

 

returning = 
var customerID = 'Table (3)'[customerID]
var orders =
CALCULATE(
    DISTINCTCOUNT( 'Table (3)'[orderId] )
    ,REMOVEFILTERS( 'Table (3)'[orderId] )
)
RETURN
IF( orders > 1, "Returning", "New" )

 


If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
user5341567
Frequent Visitor

This worked perfectly, thank you for your reply!

Deku
Continued Contributor
Continued Contributor

Deku_0-1741902829484.png

 

returning = 
var customerID = 'Table (3)'[customerID]
var orders =
CALCULATE(
    DISTINCTCOUNT( 'Table (3)'[orderId] )
    ,REMOVEFILTERS( 'Table (3)'[orderId] )
)
RETURN
IF( orders > 1, "Returning", "New" )

 


If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors