How to count # of records?

silvenwolfsilvenwolf Member Posts: 7
edited 2006-01-13 in Navision Attain
I want to count the number of records per grouping.

I tried CREATETOTALS (but it didn't work) ... I'm working with a string field.

Help please and thanks,
-S.
Computers can figure out all kinds of problems, except the things in the world that just don't add up. - James Magary

Comments

  • Captain_DX4Captain_DX4 Member Posts: 230
    I think you just want to use Record.COUNT for getting the number of records for a grouping. After the filtering is set, Record.COUNT will give you a total.

    Are you running this in a report? If so, then COUNTing the records before each grouping loops through isn't as efficient as just using an integer value incremented through the looping through of the records, as long as you don't need that value before the processing of those records.

    Cheers!
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • kinekine Member Posts: 12,562
    You can create one Integer variable and set it to 1.

    Than you can use CurrReport.CREATETOTALS(VariableName).

    In VariableName you will have the record count for each group and grand total if you will use this varibale in GroupFooter or Footer... ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Captain_DX4Captain_DX4 Member Posts: 230
    kine wrote:
    You can create one Integer variable and set it to 1.

    I'm not sure what you are doing here.

    I tried a test to just output a list of records from Table 18, creating a basic report using the wizard. I did the setup you suggested, and the first problem I encountered was that CREATETOTALS didn't want to take an integer type variable. Next, adding the value in the GroupFooter didn't automatically update.

    For this suggestion, did you mean it would be totalled automatically, or is there more setups/coding that will make this solution work?

    Cheers!
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • kinekine Member Posts: 12,562
    Sorry, create decimal variable...

    Yes, if you use CREATETOTALS with some variable, the variable value will be summed after end of OnAfterGetRecord. It is same like TotalFields property for table fields but only with some global variable...

    The CREATETOTALS must be in OnPreDataItem section...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Captain_DX4Captain_DX4 Member Posts: 230
    Ok, I've done all that you've described so far. Now, the only way for variables to automatically increment that I've seen is to actually display them in one of the body sections. I could, of course, do that, but the original question as I read it was just to get a count. I'm not even 100% sure the original request was about a report! *wink*

    Thanks for the info!
    Kristopher Webb
    Microsoft Dynamics NAV Developer
  • kinekine Member Posts: 12,562
    If it is about grouping and CREATETOTALS it is about report... ;-)

    The CREATETOTALS do not need to Show the value to be counted.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.