web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to find the same value from container

(1) ShareShare
ReportReport
Posted on by 230
Hi Team.
Below is container value
Container con1 = [A,B,A,A,A,A,B,A,B,B,C,B,B,C,B,D]
How to count same value from container?
Example;
A is repeating 6 time.
Output: A = 6
B is repeating 7 time.
Output: B = 7
C is repeating 2 time.
Output:  C = 2
D is 1 time.
Output:  D = 1
 
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    238,552 Most Valuable Professional on at
    You need to take values one by one and calculate what you need. If you don't know how to work with containers, the relevant documentation page (
     
    The implementation might look like this:
    int counter;
    
    for (int i = 1 ; i <= conLen(con1) ; i++)
    {
        str value = conPeek(con1, i);
        if (value == 'A')
        {
            counter++;
        }
    }
  • GirishS Profile Picture
    27,829 Moderator on at
    Hi,
     
    I think without know the value in the container it's hard to get the report you wanted. 
    As code provide by the martin you need to know the value in the container to increase the counter value.
    One workaround without hardcoding will be - Creating table with string field - Loop through the container using for loop and insert the values into the table.
    Later add a while select statement with count of RecId and group by the field where you inserted the container value.
    I am not sure this will work but you can give it a try - But this is time consuming one as it requires insert record in the table and adding while select to the same table.
     
    Thanks,
    Girish S.
  • Martin Dráb Profile Picture
    238,552 Most Valuable Professional on at
    If we wanted to get count of all distinct values, I would use a Map object rather then involving database. The overhead of writing to database and reading from there would be too big, IMHO.
  • CU21091228-0 Profile Picture
    230 on at
    Hi Martin,
     
    Could you please provide the sample code?
  • Martin Dráb Profile Picture
    238,552 Most Valuable Professional on at
    Dear User, what should the sample code show? Do you mean that you don't know how to use Map class and you failed to find the information on internet?
     
    If so, look at Collection Classes "Map". The example there covers the same scenario as yours.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 673 Super User 2025 Season 2

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 673 Super User 2025 Season 2

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 391 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans