Outputting only unique values

I have some data coming from my database that looks like this

id external_id price label seats product_code imported_id
244 64 1640.00 Adults 25 c1d6278fe1b014d1b1afe8ea4d6a20cb5d5549d7 - adults
245 64 920.00 Children 6-12 25 c1d6278fe1b014d1b1afe8ea4d6a20cb5d5549d7 - children
246 64 0.00 Children under 6 25 c1d6278fe1b014d1b1afe8ea4d6a20cb5d5549d7 - infants
247 64 1640.00 Adults 25 a9623ee1f74ee77e2e22754e32fa14d18ca76ef3 - adults
248 64 920.00 Children 6-12 25 a9623ee1f74ee77e2e22754e32fa14d18ca76ef3 - children
249 64 0.00 Children under 6 25 a9623ee1f74ee77e2e22754e32fa14d18ca76ef3 - infants

I would like to pass this into a server connect repeat with an expression of query.price_options.unique('label') and show an output.
The result should be the first 3 records only, id: 244, 245, 246.
This currently works, however it seems after it only repeats the unique records, I can no longer show all the fields in the row, only the label column, which is accessible under {{$value}}.

Is that normal, or should i still be able to see the id, external_id, price, label, seats, product_code, and imported_id of only the first 3 records it repeats through.

I think you need the groupBy formatter.

query.price_options.groupBy('label')

This will create an array for each label, with a full set of values for each that have that label

Unique is just like the ‘values’ formatter but removes any duplicates. The result is just an array of the field values

2 Likes

Thanks @bpj that worked perfectly, appreciate it.

1 Like