Forum Discussion

Colossal8333's avatar
Colossal8333
New Contributor II
2 months ago

Filter in map after aggregate & group by

Hi,

I am using an Aggregate step with a Group By and I am trying to get a value based on another object's value.

e.g. in the below example, I'd like to return the last_updated value where status = complete i.e. "2025-01-01"

I tried this but it just returns true/false:

$status == "Complete" ? $last_updated : null

```

[
    {
        "status": "Complete",
        "last_updated": "2025-01-01"
    },
    {
        "status": "Pending",
        "last_updated": "2025-05-01"
    }
]

```

Any help would be much appreciated!

Thanks

3 Replies

  • SpiroTaleski's avatar
    SpiroTaleski
    Valued Contributor

    Colossal8333​ 

    $.filter(x => x.status == "Complete")

    It will produce new array containing only the objects where status = Complete.

    You can easily use SnapGPT in such scenarios to generate expressions based on your prompts.

    • Colossal8333's avatar
      Colossal8333
      New Contributor II

      SpiroTaleski​ SnapGPT had already provided me that option but it does not work.

      I get this error:

      • String type does not have a method named: status, found in: x.status. Perhaps you meant: substr, substring, toUpperCase, upperFirst. Resolution: Please check expression syntax and data types.
      • SpiroTaleski's avatar
        SpiroTaleski
        Valued Contributor

        Colossal8333​ 

        The expression will work only if the input data is array. I guess that, in your case the data is already split before the step where the expression is put (and that's the reason why it is not working). 

        If your data is already split, then you can filter the records using Filter Snap with the following expression: 

        $status == 'Completed'

        So only records with status = Completed will be sent further. 

        Or maybe you can share the screenshots of the pipeline and the output of the snap before the expression is applied, so I will have a better understanding of the current issue.