Find unique entries, count them than iterate for each row in html table.

Find unique entries, count them than iterate for each row in html table.

Hello,

I have data within my form, we'll call it base_data,  in the following format:

Reciept_Type
(string/picklist)
status agentid
(picklist stored .toString() in input.agentid, thus stored as record ID)
digital active 23115441
no receipt inactive 231154323
digital active 231154323
paper active 231154323
no receipt active 231154323
no receipt active 231154323
paper inactive 23115499
no receipt active 231154102
paper inactive 231154323
no receipt inactive 23115499899

I have an html view in this format with a parameter called AGENTID  being passed, which dictates the view of the html table:

Tickets for agent  231154323
Receipt_Type Receipt Count
Digital 1
Paper 3
No Receipt 2

I am attempting to use the following code to fetch, display and sum the unique receipt types : This is the code that i have tried using:
  1.                                     <table>
  2.                                         <tbody>
  3.                                             <tr>
  4.                                                 <th>Tickets for agent 323</th>
  5.                                             </tr>
  6.                                             <tr>
  7.                                                 <th>Receipt Type</th>
  8.                                                 <th>Receipt Count</th>
  9.                                             </tr>
  10. <% for each count_pmt in base_data  [(AGENTID == input.AGENTID.toLong())]
  11.     {
  12.         RCPT_NAME = count_pmt.Receipt_Type;
  13.       
  14.         RCPT_UNIQUE = base_data[( Receipt_Type == RCPT_NAME && AGENTID == input.AGENTID.toLong() )].distinct(Receipt_Type);

  15.         RCPT_COUNT = base_data[( Receipt_Type == RCPT_NAME && AGENTID == input.AGENTID.toLong() )].count(); %>
  16.                 
  17. <tr>
  18.                                                 <td style="text-align: left;"><%=RCPT_UNIQUE%></td>
  19.                                                 <td><span style="font-size: small;"><%=RCPT_COUNT%></span></td>
  20.                                             </tr>
  21.                                    <%}%>                                
  22.                                         </tbody>
  23.                                     </table>

However, the code returns the following:

Tickets for agent  231154323
Reciept_Type Receipt Count
no receipt 3
digital 1
paper 2
no receipt 3
no receipt 3
paper 2

edit: It fetches the tickets that match the AGENTID no problem, however instead of listing the unique entries and their corresponding count just once, the row iterates for every single record than lists the records count.

Is there a method other than aggregate>distinct to return the unique values or am i missing something with this code?