How to count the number of Sales Orders for each Customer

sbillysbilly Member Posts: 231
I want to count the number of Sales Orders for each Customer in the Sales header table.
In a report based on Sales header table, in the OnPreDataItem trigger I wrote this code
SETRANGE("Document Type",1);
nbre :=0;
IF FIND('-') THEN
REPEAT
nbre := nbre +1;
UNTIL NEXT =0;
But it counts me all the sales orders and not by each customer
Help Please

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    There is a flow field in customer table called "Bill-To No. of Orders" or No. of Orders
  • lvanvugtlvanvugt Member Posts: 774
    There is a flow field in customer table called "Bill-To No. of Orders" or No. of Orders
    Right :thumbsup: and use that!

    But to also help you understand why it's showing the number of all orders:
    SETRANGE("Document Type",1);
    nbre :=0;
    IF FIND('-') THEN
      REPEAT
        nbre := nbre +1;
      UNTIL NEXT =0;
    
    You only are filtering out the documents of type '1' (as you use in your code - but see below), being the orders, but not filtering out the document for a specific customer. To get that working your code should be:
    SETRANGE("Document Type",1);
    SETRANGE("Sell-to Customer No.",CustomerNo);
    nbre :=0;
    IF FIND('-') THEN
      REPEAT
        nbre := nbre +1;
      UNTIL NEXT =0;
    
    Or even much shorter
    SETRANGE("Document Type","Document Type"::Order);
    SETRANGE("Sell-to Customer No.",CustomerNo);
    nbre := COUNT;
    
    where CustomerNo is of Type Code20 holding the number of the customer you want to count for.
    Luc van Vugt, fluxxus.nl
    Never stop learning
    Van Vugt's dynamiXs
    Dutch Dynamics Community
  • sbillysbilly Member Posts: 231
    There is a flow field in customer table called "Bill-To No. of Orders" or No. of Orders
    The version of Navision that I use, doesn't contain such field.

    I want to display the number of ordes for many customer in one , and this code is only for one customer.
    SETRANGE("Document Type","Document Type"::Order);
    SETRANGE("Sell-to Customer No.",CustomerNo);
    nbre := COUNT;
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    You have to take customer dataitem first and link it to Sales Header..

    You can create those fields in your version by looking at the new version..
  • sbillysbilly Member Posts: 231
    You have to take customer dataitem first and link it to Sales Header..

    You can create those fields in your version by looking at the new version..
    Grate, Thanks for all of you.
Sign In or Register to comment.