Using unique filter on an array with multiple objects

Answered

Hi.

I am creating a function stack that takes an array with objects that have around 20 elements each from an API call. The objective is to grab 2-3 elements and use that to create aggregates.

The data source is for transactions meaning many to many, one to many and many to one relationships exist.

One of the outputs I'm looking for lifts the unique customer IDs, then aggregates the amounts for each time they have transacted at a particular cashier and returns the array, so you have a list of customer IDs and total amounts spent at the selected cashier.

The problem is that each object is unique already because each transaction has a unique ID. However the source data has a flaw in that some transactions have been double posted (it's the same exact transaction, but with it's own transaction ID.

My stack follows this process

  • Call the API and stores it into a variable Source
  • Grabs the customer IDs from Source and uses the unique filter on them and saves them in the variable IDs
  • Runs a for each loop on IDs checking Source for all instances they appear and stores them in Customer Transactions, then adds them to a new array (LIST) that combines the ID with the transaction (so you have objects that have the ID and the IDs transactions)
  • Updates the variable LIST to only have the ID and the IDs' transaction values (adding a sum to this gives me the cleaned up list)

However, the problem is some of the objects are duplicates, leading to the wrong aggregation.


I've tried to use the unique filter on the array of objects (expecting it to return all objects because they are all unique from above) which fails to run. I've however been able to get it to run on a list of elements which will also be inaccurate because there can be two transactions of the same amount at different times. I only need to exclude transactions of the same amount that take place at the same time.

2 questions,

  1. Would I be correct to assume unique filter only works on a list of elements and not a list of objects?
  2. Is there any clever way to pull this off?

1
6 replies