# Filter with criteria

**URL:** <https://community.amazonquick.com/t/filter-with-criteria/4334>\
**Category:** Q&A\
**Tags:** filters, quick-sight\
**Created:** [June 22, 2022, 6:19pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334 "2022-06-22T18:19:40Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 22, 2022, 6:19pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/1 "2022-06-22T18:19:41Z")

</div>

Hello  
I have to filter the clients that buy 3 items A, B and C together. The filters do not work because they bring customers who buy 1 or 2 or 3 items, but not only those who buy all 3. How could I do it? thanks

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [June 22, 2022, 9:10pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/2 "2022-06-22T21:10:57Z")

</div>

Hi @sanmar -

This is an interesting one, there’s no multi-select parameter/filter for ‘match all’.

Here’s a workaround that utilizes @darcoli 's [multi select parameter action](https://community.amazonquick.com/t/how-can-i-select-multiple-lines-from-a-table-and-how-could-i-then-deselect-those-items-to-exclude-them-form-the-analysis/1217)

**Step 1 - Create a ‘SelectedItemIDs’ parameter with a default value of ‘,’**

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/9/926d9e2129fac59d2f8f343e60fc0bfc44bffb9f.png)

**Step 2 - Create a ‘c\_updated\_selected\_items\_id’ calculated field and add to a table visual group by.**

```auto
ifelse(
  locate(${SelectedItemIDs}, {item_id}) > 0, replace(${SelectedItemIDs}, concat({item_id},','), ''),
  concat(${SelectedItemIDs},{item_id},',')
)

```

**Step 3 - Create ‘c\_in\_selected\_item\_ids\_flg’ calculated field and use in conditional formatting.**

```auto
ifelse(locate(${SelectedItemIDs}, {item_id} ) > 0 , 1, 0)

```

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/a/abc19394c9bb7868360c36742a38f1df3e9d8b3d.png)

**Step 4 - Add ‘c\_all\_items\_flg’ calculate field to use as filter.**

```auto
// hard coded 10 matches
ifelse(
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',2),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',3),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',4),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',5),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',6),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',7),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',8),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',9),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',10),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',11),1,0),[{client_id}],PRE_AGG)
=strlen(replace(${SelectedItemIDs},',','')),'Y','N')

```

**Result:**  
 ![2022-06-22_17-09-26 (1)](https://d1wl4jav5dp96l.cloudfront.net/original/2X/3/32c18033abb71a996384ce719aeeff62e2cb8618.gif)

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 23, 2022, 12:36pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/3 "2022-06-23T12:36:54Z")

</div>

> [@robdhondt](#):
>
> `e`

Hi robdhondt  
Regarding step 4: I would need to count the customers -without repetition- that meet the criteria of buying all the items together Could you help me with this?thanks in advance

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [June 23, 2022, 12:51pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/4 "2022-06-23T12:51:49Z")

</div>

Hi @sanmar -

Sure. Quick Sight has some helpful If functions, you can use [distinct\_countIf](https://docs.aws.amazon.com/quicksight/latest/user/distinct_countIf-function.html) using the “c\_all\_items\_flg” calculated field you created in step 4.

**Example:**

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/b/b71cc22a1ec22cf7622d3cc75d01c0dc29b5f247.png)

Note: distinct\_countIf is the same as doing `distinct_count(ifelse({c_all_items_flg}='Y',{client_id},null))` but this helpful function keeps things a bit cleaner.

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 23, 2022, 6:39pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/6 "2022-06-23T18:39:37Z")

</div>

Hi Robdhondt,thank you very much for your help ! Step 4 gives me an error Look

 ![step4](https://d1wl4jav5dp96l.cloudfront.net/original/2X/2/2a7d3b8498ca0811bd96af1a32a81e5382148849.jpeg)

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [June 23, 2022, 8:09pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/7 "2022-06-23T20:09:18Z")

</div>

Hi @sanmar -

You will get that error message if you didn’t set “,” as the default value for the parameter. The functions throw the error because the expression is null. Is one set?

![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/0/081cc9d2953999d88ba2ab769555a7f3ffb17503.png)

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 23, 2022, 10:31pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/8 "2022-06-23T22:31:54Z")

</div>

> [@robdhondt](#):
>
> You will get that error message if you didn’t set “,” as the default value for the parameter. The functions throw the error because the expression is null. Is one set?

Hi robdhondt,  
Yes. I set the parameter up as you said I show you

 ![parameter](https://d1wl4jav5dp96l.cloudfront.net/original/2X/b/b6ea8f1ec174e3afeeea05badf39ca60f38ae416.jpeg)

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [June 24, 2022, 1:41pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/9 "2022-06-24T13:41:09Z")

</div>

Hi @sanmar -

Can you paste the actual calculated field? It’s odd that you are getting the error.

I would try working backwards through the calculated field and reducing the complexity until you find the section causing the error.

For example, change the strlen section to a static integer. If the error goes away you know it has something to do with that section, etc

```auto
// hard coded 10 matches
ifelse(
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',2),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',3),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',4),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',5),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',6),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',7),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',8),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',9),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',10),1,0),[{client_id}],PRE_AGG)+
maxOver(ifelse({item_id}=split(${SelectedItemIDs},',',11),1,0),[{client_id}],PRE_AGG)=10,'Y','N')

```

Then try the inverse, and see if the error goes away. This is how I typically debug lengthly/complex calculated fields.

```auto
ifelse(10=strlen(replace(${SelectedItemIDs},',','')),'Y','N')

```

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 24, 2022, 6:08pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/10 "2022-06-24T18:08:23Z")

</div>

> [@robdhondt](#):
>
> Can you paste the actual calculated field? It’s odd that you are getting the error.
> 
> I would try working backwards through the calculated field and reducing the complexity until you find the section causing the error.
> 
> For example, change the strlen section to a static integer. If the error goes away you know it has something to do with that section, etc

Hi robdhondt

I don’t understand the meaning… What is the “actual calculated field”? could you give me an example please? Thank you

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [June 24, 2022, 6:17pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/11 "2022-06-24T18:17:39Z")

</div>

@sanmar - The text instead of an image.

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 24, 2022, 6:23pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/12 "2022-06-24T18:23:37Z")

</div>

ifelse (

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,2),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,3),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,4),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,5),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,6),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,7),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,8),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,9),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,10),1,0),[{codcliente}],PRE\_AGG+

maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,11),1,0),[{codcliente}],PRE\_AGG

=strlen(replace(${selecteditemsids},‘,’,‘’)),‘Y’,‘N’)

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [June 24, 2022, 10:28pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/13 "2022-06-24T22:28:30Z")

</div>

@sanmar -

I missed it in your original image. You are missing the closing parenthesis in all your maxOver functions.

Like this.

ifelse(  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,2),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,3),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,4),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,5),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,6),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,7),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,8),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,9),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,10),1,0),[{codcliente}],PRE\_AGG **)** +  
maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,11),1,0),[{codcliente}],PRE\_AGG **)**  
=strlen(replace(${selecteditemsids},‘,’,‘’)),‘Y’,‘N’)

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 26, 2022, 6:05pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/14 "2022-06-26T18:05:54Z")

</div>

@robdhondt Hi , thank you very much, it worked! But I didn’t get what I need. I used this: **distinct\_countIf({codcliente}, {c\_all\_items\_flg}=‘Y’)** to count clients

In the exercise that I did, I took 3 product codes: A, B and G. I need to find how many customers bought the 3 codes (together) in a period of time (month, quarter and year). What I get with this calculated field is the number of customers who bought any of the 3 (=120 clients/month), but not only those who bought all 3 (=just 2 clients/month !!). Maybe I’m doing something wrong?, I don’t know… Thanks

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [June 26, 2022, 10:15pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/15 "2022-06-26T22:15:10Z")

</div>

> [@robdhondt](#):
>
> maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,2),1,0),[{codcliente}],PRE\_AGG **)**

Hi @sanmar -

The way the LAA calculation is partitioned by ‘codcliente’. Which means if the client ever purchased, if you want check by (month, quarter, and year) you need to add that to the partition argument.

example:  
`maxOver(ifelse({codsku}=split(${selecteditemsids},‘,’,2),1,0),[{codcliente},{date_grain}],PRE_AGG)`

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 27, 2022, 2:10pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/16 "2022-06-27T14:10:15Z")

</div>

robdhondt  
Hello, Could you please tell me a bit about each part of this calculated field? So that way I can understand it, and I can adapt it correctly to what I need. Thank you!!

---

<div class="post-metadata">

**Author:** ![robdhondt](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/robdhondt/32/194_2.png) [@robdhondt](https://community.amazonquick.com/u/robdhondt)\
**Post date:** [June 27, 2022, 3:32pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/17 "2022-06-27T15:32:59Z")

</div>

Hi @sanmar -

The Quick Sight docs for maxOver explain this really well see [maxOver - Amazon QuickSight](https://docs.aws.amazon.com/quicksight/latest/user/maxOver-function.html)

And for some more real life examples check out this blog [Calculated fields, level-aware aggregations, and evaluation order in Amazon QuickSight | AWS Big Data Blog](https://aws.amazon.com/blogs/big-data/calculated-fields-level-aware-aggregations-and-evaluation-order-in-amazon-quicksight/)

The LAA calculations are easier to understand if you have SQL/windowing functions experience. You can think of it as a “window” into your dataset. In the case you want to look at subset that is just your client and period of time.

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 27, 2022, 11:18pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/18 "2022-06-27T23:18:31Z")

</div>

Hi  
I’m not a programmer and I don’t have experience with SQL. I thought maybe I’d find an easier solution to this issue here. Well I’ll keep looking then. Cheers

---

<div class="post-metadata">

**Author:** ![sanmar](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/sanmar/32/1984_2.png) [@sanmar](https://community.amazonquick.com/u/sanmar)\
**Post date:** [June 30, 2022, 12:37pm UTC](https://community.amazonquick.com/t/filter-with-criteria/4334/19 "2022-06-30T12:37:29Z")

</div>

@robdhondt Hi  
I was finally able to do what you suggested I ask you:

1. when I add the filter ‘c\_all\_items\_flg’ and choose the codskus, I get a message that “No data” No data found for the visual element. Not one, not two, three codsku works  

2. How should I prepare this filter ‘c\_all\_items\_flg’ to filter the group of 3 codsku?thanks
