Sorting Distinct Values by Date_of_Invoice

Sorting Distinct Values by Date_of_Invoice

Hey I have a table that I want to display, and right now it's sorting by the name of the trust or company so the data isn't in the correct order. I need the data to display by the invoice date, but I can't figure out for the life of me how to get it to display in the correct order.

The code so far is as follows: 
  1. TrustDistinct = Finances[Display_Name == searchParam && Line_Item.containsIgnoreCase("Trust")].distinct(Line_Item);
  2. for each  Expense in TrustDistinct
  3. {
  4. // Add all of same trust together to get total for each field
  5. DisbursementFromTrust = Finances[Display_Name == searchParam && Line_Item == Expense].sum(Amount);
  6. DisbursmentFromTrustFormatted = "$ " + DisbursementFromTrust.round(2);
  7. //TMCo is equal to Trust Management Company
  8. // listOfDates = List:date();
  9. // listOfDates.add(Finances[Display_Name == searchParam].Date_of_Invoice);
  10. // datesSorted = listOfDates.sort(false);
  11. DisbursementDateFromTrust = Finances[Display_Name == searchParam && Line_Item == Expense] sort by Date_of_Invoice;
  12. AttorneyFees = Finances[Display_Name == searchParam && Type == "Attorney Fees" && Line_Item == Expense].sum(Amount);
  13. AttorneyFeesFormatted = "$ " + AttorneyFees.round(2);
  14. AmountToClientExpenses = Finances[Display_Name == searchParam && Type == "Client Expenses" && Line_Item == Expense].sum(Amount);
  15. AmountToClientExpensesFormatted = "$ " + AmountToClientExpenses.round(2);
  16. //TotalBalancePaid = AttorneyFeesFormatted + AmountToClientExpensesFormatted;
  17. DisbursementToClient = Finances[Display_Name == searchParam && Type == "Disbursement to Client" && Line_Item == Expense].sum(Amount);
  18. DisbursementToClientFormatted = "$ " + DisbursementToClient.round(2);
  19. DisbursementToMedicare = Finances[Display_Name == searchParam && Type == "Medicare / Medicaid Liens" && Line_Item == Expense].sum(Amount);
  20. DisbursementToMedicareFormatted = "$ " + DisbursementToMedicare.round(2);
  21. //Check No. Need to configure
  22. //DateOfDisbursement = Finances[Display_Name == searchParam && Type == "Disbursement to Client" && Line_Item == Expense];
  23. //Trust = Finances[Display_Name == searchParam && Type == "Disbursement to Client"];
  24. %>
  25. <div class="divTableRow">
  26. <div class="divTableCell1"><%=Expense%></div>
  27. <div class="divTableCell1"><%=DisbursmentFromTrustFormatted%></div>
  28. <div class="divTableCell1"><%=AttorneyFeesFormatted%></div>
  29. <div class="divTableCell1"><%=AmountToClientExpenses%></div>
  30. <div class="divTableCell1"><%=DisbursementToMedicareFormatted%></div>
  31. <div class="divTableCell1"><%=DisbursementToClientFormatted%></div>
  32. <div class="divTableCell1"><%=DisbursementDateFromTrust.Date_of_Invoice%></div>
  33. </div>