How to use matching values from 2 arrays in a filter step - intersection()

Hi all!

I hope you are doing well. I am trying to set up two filters in a scenario that needs to compare two arrays. One from an API and the other from Airtable - I have added steps to create array variables in Make (because map() would not recognize the array directly) and to make sure they are structured the same way.

All I need is a filter step, where if value x from arrayAirtable is found on arrayAPI that particular track continues. This filtering needs to happen in an embedded iteration, so doing the matching with another iteration step does not seem feasible to me.

Is there any way (other than iterating over both arrays to find matches) to compare two arrays in make? Ideally, as an output get to know whether a value from “array A” exists on “array B”?

Thank you for any help! :folded_hands:

Welcome to the Make community!

You’ll have to aggregate one array first, so that during the iteration of the second array, you can compare each value from the second array to see if it exists in the first.

Use the “Array operators: Contains” operator in the filter.

Hope this helps! Let me know if there are any further questions or issues.

— @samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

Hi @samliew,

Thanks for the quick response, but that solution does not seem to work.
I also don’t understand why would I need to aggregate the array first? That seems just to create another embedded array?

If I do arrayA contains arrayB as a filter - it never succeeds even if arrayB only has 1 value and that exact value is also findable on arrayA. The thing is I need it to actually do more than that, because arrayB can have multiple values - and only 1 needs to be on arrayA for the filter to see it as “successful”.

If it was possible to do intersection() than I would have done that, and filter on the length of that intersection() - so if matching values >0 then continue - but Make does not seem to have that option. I also need to do this for 2 arrayB’s which is why I want to avoid more iteration steps as I worry that won’t work.

All I need is the ability to something like intersection() (Python Set intersection() Method)

I have ended up doing it with two additional iteration steps - making the scenario longer but fortunately not too long to be saved. That does mean I have 5 iterations in this scenario now - but it works. Would be great if intersection() or find() could become a function for the filter, so all these iterations would no longer be required.

2 Likes

This can be achieved with just a single module, as you can also run JavaScript and Python in supported modules.

If you need further assistance with this, feel free to submit a new question as this one is resolved.

Hope this helps! Let me know if there are any further questions or issues.

— @samliew