The most popular item in the table

Hi. I am having a table of identifiers and elements on how to calculate the number of entries with the same identifier to find out which one is most popular.
I understand that I need to use filters

SALESLIST.SETFILTER ("No", '<>% 1', "No");
SALESLIST.SETRANGE (ID, ID);

but I can not find a solution to calculate the most popular record

w6tt7vs16vyb.jpg

Best Answer

Answers

  • KTA8KTA8 Member Posts: 397
    using setrange (over ID) and count, you should be able to do it; but I'm not getting the approach...
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Not exaclty sure if this is what you are after but the bit below will calculate
    number of occurrences per ID
    TempBuf : Record 368 TEMPORARY;
    
    if SALESLIST.findset THEN
    REPEAT
     CLEAR(TempBuf);
     TempBuf.Code := SALESLIST.ID;
     IF NOT TempBuf.FIND THEN 
      TempBuf.INSERT;
       
     TempBuf.Level += 1;
     TempBuf.MODIFY;
    UNTIL  SALESLIST.NEXT = 0;
    
    TempBuf.SETCURRENTKEY(Level); 
    TempBuf.ASCENDING(FALSE); //TempBuf is now ordered from the most popular (most frequent) ID 
                              //to least popular/least frequent
    
    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.