Count number of record

Horse06Horse06 Member Posts: 496
Hi, I create a report on the sales order and I want to count how many orders based on the sales number. If the sales number data type is text, how to calculate the total number? Thanks in advance!

Comments

  • ara3nara3n Member Posts: 9,257
    FOR I := 1 TO STRLEN("No.") DO BEGIN
      IF EVALUATE(TempInt,FORMAT("No."[I])) THEN
        TempStr += FORMAT("No."[I]);
    END;
    
    evaluate(TempInt,TempStr);
    message('You've created ' + TempStr + ' Sales order Number');
    


    You can use TempInt as integer and do what you want with it.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Horse06Horse06 Member Posts: 496
    Thanks for your quick response! I like my output of report like this
    Sales Order No.
    SO110
    SO112
    SO113
    ___________
    Total 3 Orders
  • ara3nara3n Member Posts: 9,257
    Oh in that case in your footer section add a text box and set sourceexpr to be


    'Total ' + format("Sales header".Count) + ' Orders'
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Horse06Horse06 Member Posts: 496
    Thanks! The function of Count is used on the record. If I have several Sales: A, B, C, how to write report like this:
    A:
    S110
    S112
    _____
    2 Orders

    B:

    S113
    _____
    1 Orders

    C:
    S220
    S230
    S440
    S250
    ____
    4 Orders
    Thanks in advance!
  • krikikriki Member, Moderator Posts: 9,118
    You need the total at the end of the loop. So you can do it with a counter.
    "OnPreDataItem":
    intCounter := 0;
    

    "OnAfterGetRecord":
    intCounter += 1;
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Horse06Horse06 Member Posts: 496
    Thank you, kriki! It coun the total sales order, but it didn't work it out on the sales order of the separate salesperson. Would you provide me the detailed info. Thank you very much Kriki!
  • AlbertvhAlbertvh Member Posts: 516
    Then you should sort by and set groupyotals by salesperson
  • kinekine Member Posts: 12,562
    1) CurrReport.CREATETOTALS(intCounter) in OnPreDataitem
    2) intCounter := 1 in OnAfterGetRecord (yes, just assign, not increase)
    3) Everywhere you print intCounter you will have correct grand total (in Footer) and totals (in groupfooter)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Horse06Horse06 Member Posts: 496
    Thanks! intCounter declared without linking to any value seems not working. I tried the following and it didn't work either,

    FOR I := 1 TO STRLEN("salesperson code") DO BEGIN
    IF EVALUATE(TempInt,FORMAT("salesperson code")) THEN
    strSales += FORMAT("Salesperosn Code.");
    END;

    Any probelms here? Thanks!
  • AlbertvhAlbertvh Member Posts: 516
    If you are using the Sales Invoice Header table (112) then you need to set the following properties

    1) DataItemTableView Salesperson Code (create a key if it doesn't exist)
    2) GroupTotalFields Salesperson Code

    then do as Kine said
    1) CurrReport.CREATETOTALS(intCounter) in OnPreDataitem
    2) intCounter := 1 in OnAfterGetRecord (yes, just assign, not increase)
    3) Everywhere you print intCounter you will have correct grand total (in Footer) and totals (in groupfooter)

    Ensure that in your sections you have GroupHeader and GroupFooter defined and this code on each OnPreSection

    CurrReport.SHOWOUTPUT :=
    (CurrReport.TOTALSCAUSEDBY = "Sales Invoice Header".FIELDNO("SalesPerson Code"));

    This should do the trick. :wink:
  • Horse06Horse06 Member Posts: 496
    Thank you Albertvth! It works.
  • SavatageSavatage Member Posts: 7,142
    Don't you just love whan a plan comes together!

    \:D/

    This forum rules!
  • Horse06Horse06 Member Posts: 496
    Hi expert. Is there any way to count just the debit record in the customer account, since debit and credit are considered one entry if we count the record. The Fact is Debit and Credit are not equal all the time and we just want to count how many DEBITS one customer has and how to do it? Thanks in advance!
  • DenSterDenSter Member Posts: 8,307
    Savatage wrote:
    Don't you just love whan a plan comes together!
    Yes these types of threads are very cool to watch :mrgreen: it's like working on a project together.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Horse06 wrote:
    Hi expert. Is there any way to count just the debit record in the customer account, since debit and credit are considered one entry if we count the record. The Fact is Debit and Credit are not equal all the time and we just want to count how many DEBITS one customer has and how to do it? Thanks in advance!

    Do you mean customer entries? The invoices have another Document type than the credit memo's.

    Maybe you can use this to count the records.
  • RoiRoi Member Posts: 33
    ya I agree with u
    DenSter wrote:
    Savatage wrote:
    Don't you just love whan a plan comes together!
    Yes these types of threads are very cool to watch :mrgreen: it's like working on a project together.
Sign In or Register to comment.