Filter Query to only show unique address and return to a table

We have a query that is pulling from a retool database. When we run the query we get 198 results, in side of thee results we have address and branches. I need to filter this query down to only show the unique branches.

I have built a javascript that filters down the results the way I want them but I can not get this returned to a retool table.

Here is the javascript I have built:
Query_Branches.trigger({
// You can use the argument to get the data with the onSuccess function
onSuccess: function (data) {
//console.log("Successfully ran!");

// Output the structure of the data to the console for inspection
//console.log(data);   

const filteredLocations = data.id.map((id, index) => ({
  id,
  name: data.name[index],
  city: data.city[index],
  state: data.state[index],
  address: data.address[index],
  suite: data.suite[index],
  customer_id: data.customer_id[index],
  latitude: data.latitude[index],
  longitude: data.longitude[index],
  zipcode: data.zipcode[index],
  branch_number: data.branch_number[index],
  location_id: data.location_id[index],
  master_branch: data.master_branch[index],
}));

//console.log(filteredLocations);

        const uniqueAddresses = [];
        const uniqueFilteredLocations = [];
        
        filteredLocations.forEach(location => {
          if (!uniqueAddresses.includes(location.address)) {
            uniqueAddresses.push(location.address);
            uniqueFilteredLocations.push(location);
          }
        });
        
        console.log(uniqueFilteredLocations);

    
return uniqueFilteredLocations;

},
});

Console log shows the data inside of uniqueFilteredLocations but I can not return this. I do not get a Output when I run the query.

What am I missing and how can I get this to show an output?

What happens if you use the data from the query as the table source with {{Query_Branches.data}}?

The results of queries won't show in the query/code area when they are triggered from the app (AFAIK) but the data should be there as part of the query.data value

Hi @chadxxxxx, the docs here may be helpful for your issue.

You could try to extract the filteredLocations functionality outside the .trigger() call. Then run await query.trigger(), and perform the filter function on the data that it returns. Here's a very simplistic example that worked for me:

// Sorting functionality
const reorderArrayByVote = (array) => {
  return array.sort((b, a) => {
    return a.upvotes - b.upvotes;
  });
};

// Trigger getQuestions query
let questionsData = await getQuestions.trigger()

// Sort the result
let reorderedResult = reorderArrayByVote(questionsData);

// Return final dataset
return reorderedResult