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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
JeroniJamboni
Advocate I
Advocate I

Count number of orders per customer in column

Hi Guys,

 

I'm relatively new with dax formula's and trying to work my way through the data I have to become a real DAX-Master;). Bought the book and visit this website regularly, which is very helpfull! At the moment however i seem to have a lot of difficulties trying with finding returning customers. I know that there are a lot of posts out there, which propably know already, but i can't seem to find a solution to my question.

 

I have a calculated sales table with:
Orderdate, OrderID, ProductID, CustomerID, Orderstatus
(by the way: Multiple order lines per order ID)

I would like to know how i could get a calculated column which calculates the number of previous orders of this customers. I would really like to have it filtered to order state. Only orders with the "completed"-status should be counted. 

Hope my question is clear. I tried almost everything. I can't find a good solution. I hope you guys can be of any help.

Jeroen

1 ACCEPTED SOLUTION

Hi,

 

Thanks for you answer. Works great to find the total number of orders, but i wanted to get the sequential number of the order. 

I found this solution, which works great!

Order sequence = 

COUNTROWS(
    FILTER(
        CALCULATETABLE(
            TableOrder;
            ALLEXCEPT(TableOrder;TableOrder[CustomerID])
        );
        TableOrder[Orderdate] < EARLIER(TableOrder[Orderdate])
        &&
        TableOrder[Orderstate] = "Complete"
    ))+1

By the way. The +1 is used to eliminate the zero's which it returns for first-time orders;).

Thanks anyway for your help. Got me thinking:D

Jeroni

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

HI @JeroniJamboni,


I think it will be help if you provide some sample data to analysis.


Below is the sample measure which I haven't test on real data, maybe you can try it if it suitable for your requirement:(create table visual with 'customer id' and below measure)

Order Count =
CALCULATE (
    DISTINCTCOUNT ( Table[OrderID] ),
    FILTER (
        ALL ( Table ),
        [CustomerID] = MAX ( Table[CustomerID] )
            && [Orderstatus] = "completed"
    )
)

 

Regards,

Xiaoxin Sheng

Hi,

 

Thanks for you answer. Works great to find the total number of orders, but i wanted to get the sequential number of the order. 

I found this solution, which works great!

Order sequence = 

COUNTROWS(
    FILTER(
        CALCULATETABLE(
            TableOrder;
            ALLEXCEPT(TableOrder;TableOrder[CustomerID])
        );
        TableOrder[Orderdate] < EARLIER(TableOrder[Orderdate])
        &&
        TableOrder[Orderstate] = "Complete"
    ))+1

By the way. The +1 is used to eliminate the zero's which it returns for first-time orders;).

Thanks anyway for your help. Got me thinking:D

Jeroni

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors