Here’s a quick tip for filtering portals with multiple filter terms.
Recently, I needed to filter a portal where I initially thought that each filter term should individually match an entry. The field to be filtered was a multi-key field containing attributes of an item, such as:
– 16 GB
– USB C
– Red
So, I set up a global field as a multi-key (text) field where the selected terms were also stored as a list:
Main::MultiKeyField_Filter
This way, users could toggle these terms to create their desired filter.
The filtering formula for this case was very simple:
FilterValues ( Portal::Term ; Main::MultiKeyField_Filter ) ≠ ""
However, the requester didn’t want to filter for each term individually (which would mean that with an increasing number of filter terms, you’d get more and more results). Instead, they wanted all filter terms to collectively form the filter.
So, instead of filtering individually for:
– 16 GB
– USB C
– Red
(i.e., every match that contains either *16 GB*, *USB C*, or *Red*), they wanted to filter for the combination of *16 GB* AND *USB C* AND *Red*.
I concluded that the simplest way to achieve this would also involve using `FilterValues`, but now based on the number of filter terms. The idea is to check whether the number of filtered elements matches the number of filter terms from the `MultiKeyField_Filter`. If so, every filter term has a match in the field being filtered:
ValueCount ( FilterValues ( Portal::Term ; Main::MultiKeyField_Filter ) ) = ValueCount ( Main::MultiKeyField_Filter )
This is also very easy to implement, even if the terms in the portal table are not stored as a multi-key field. You can simply create a multi-key filter as an indexed calculation field and apply the filter to it.