I have an expression that needs deduplication of a nested property. We have a working solution right now, but we’d like to optimise this as much as possible because of the enormous size of the answers table.
What I need
A list of answers of unique questions from activity (forms), but these forms have an overlap in questions (e.g. some questions are answered in mulitple forms, but always have the same answer).
The following expression performs fine, but is not deduplicated on the question.
@David, hello! Don’t you use a QuestionConnection data model? It is the linked table between Questions and Answers, so the question and answer records could be the same but attached to the different question connections.
But obviously you do not want to have a list of questions but their answers.
So replace the “this” with a answers:first({}) that gets the first relevant answer for the parent question, like so:
The result should be a list of relevant answers.
I added the sorting id.desc so you always get the newest answer.
I am not sure about the this.activity.in([]). Please double-check it. I added another “parent”, but feel free to adjust the filtering of the answers:first({}).
Write the expression that return the non deduplicated list
Add an extra boolean:not(exists)-filter to the list of filters where the list-parameter is exactly the same as the list expression (ofcourse add an extra parent if needed) of the first step and expand the filter with id.isgreater(parent.id)
For step 2 we expand the filter of the first expression with boolean:not(answers:exists({}). In this list {} we copy the expression of step 1, add an extra parent if needed, and extend the filter with id.isgreater(parent.id). Result is as follows: