External Query but for Grouping / Aggregating

Options

The external query capability for using a JSON structured input as a filter criteria is great, and provides significant flexibility with how front end app's can interact with Xano data.

But what about when the front end also needs to instruct Xano on what fields to group and aggregate by for a query?

It appears that currently it is only possible to "hardcode" the fields that Xano should group and aggregate by for a particular query.

Is there any way to dynamically instruct Xano during runtime of a query to group and aggregate on certain fields?

Comments

  • nocodetalks
    nocodetalks Member ✭✭
    Options

    I don't think it is possible to dynamically pass the key natively.

    But you can create your logic, though.

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options

    Hey @Damien Ryan, @nocodetalks is on the right track. Aggregate fields aren't dynamically chosen, so you would want to set up a function stack with conditionals to indicate which query to run based on your changing fields you wish to aggregate... Alternatively, you could also have separate endpoints that aggregate specific things.

  • espptyltd
    Options

    Thanks for your response @NoCodeLearner and @Michael Udinski .

    I still think what I want to do is possible in Xano, but based on your responses I'll need to look at a different way of doing it.

    Instead of building the group and aggregate by directly into the query records query, I'm going to try and build it in a function that is called after the initial function stack has performed a filtered query.

    This will provide the function with an array of filtered results, which I will then use a combination of loops to group the results, and then filters to perform the aggregate steps.