How to count distinct records in a table?

Nav_il
Member Posts: 30
Hi All,
I have a table with "Table Name,Employee No.,Line No." as keys. You can enter the same employee no. more than once in this table. Now i want to count the employee numbers in this table onces. for example, If i have 1222, 1222, 1222, 1333, 1333, 1444 employees numbers recorded in the table, i want to count 1222 as one record, 1333 as one and 1444 as one. So i should have a total of 3 records. Also, i want to do this counting withing a specified date range. Say i want all the records in the table withing say 010117...010317 date range which i get using Filter := "Employee".GETFILTERS; expression in the onPreReport. Any idea on how to do this please? Thanks.
I have a table with "Table Name,Employee No.,Line No." as keys. You can enter the same employee no. more than once in this table. Now i want to count the employee numbers in this table onces. for example, If i have 1222, 1222, 1222, 1333, 1333, 1444 employees numbers recorded in the table, i want to count 1222 as one record, 1333 as one and 1444 as one. So i should have a total of 3 records. Also, i want to do this counting withing a specified date range. Say i want all the records in the table withing say 010117...010317 date range which i get using Filter := "Employee".GETFILTERS; expression in the onPreReport. Any idea on how to do this please? Thanks.
0
Best Answer
Answers
-
Take one EmpVar
Now OnAfterrecord write this condition
IF EmpVar <> Table."Employee NO" THEN
BEGIN
EmpCount +=1;
END;
EmpVar := Table."Employee NO";
Do not clear any var.
And apply filter on predataitem0 -
Thanks ishyampandey . However, you cannot do this "IF EmpVar <> Table."Employee NO"". It means you are comparing an integer (EmpVar) with a code (Employee number). Also why apply filter on Predataitem? I have already appied it on onPreReport.0
-
You need to build a logic, there's no any keyword as distinct like SQL which exist here.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Hi RockwithNav, thanks for the comment. Yes, I am aware that there is no keyword like DISTINCT, and I have been thinking of logics which are not working. For example, I tried to compare previous Employee number with the current one, if they are the same, I skip counting and if they are not the same, I count. But I don't know how to get previous employee number which is a code and compare it with the current employee number. Do you know how to do that?
0 -
-
No, My Employee No. is a Code datatype.0
-
-
Thanks ishyampandey. This works.0
-
Just build a Query. Fast and simple. Oeps.. Just say this is for the classic Client.0
-
you can use temp table to store each record, and insert field you wish to count distinct to primary key and count the temp table.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions