# Filtering with a value from a previous node

**URL:** <https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686>\
**Category:** Questions\
**Tags:** expressions, jmespath\
**Created:** [September 14, 2022, 1:44pm UTC](https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686 "2022-09-14T13:44:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Batijko](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/batijko/32/17185_2.png) [@Batijko](https://community.n8n.io/u/Batijko)\
**Post date:** [September 14, 2022, 1:44pm UTC](https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686/1 "2022-09-14T13:44:47Z")

</div>

Hey everyone,

I’m pretty new to n8n and have a simple question regarding filtering inside the expression editor and was not sure if it’s possible or not. I would like to add a value from a previous node to a filtering process of the current node. Here is a short example:

Ideally, I would like to replace the value inside the second Set node with the variable from node 1. So something like: {{$jmespath($json.data, “[?email== **‘Variable from Set1’**].link | [0]”)}}.

Is this possible or do I have to build a different workflow? I would appreciate any kind of help.

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [September 14, 2022, 2:44pm UTC](https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686/2 "2022-09-14T14:44:02Z")

</div>

Hi @Batijko, welcome to the community! This is possible, you can reference any previous node in your workflow using an expression such as `{{ $node["Node name"].json["field"] }}`.

You can write these expressions manually (which is especially useful when using them in a more complex context like in your JMESPath example) or simply click your way through the expression editor like so (after running your previous node):

![Recording 2022-09-14 at 16.43.48](https://europe1.discourse-cdn.com/n8n/original/3X/4/a/4a7a60a5120e9c128a746cb467d39f46cf7b7d75.gif)

---

<div class="post-metadata">

**Author:** ![Batijko](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/batijko/32/17185_2.png) [@Batijko](https://community.n8n.io/u/Batijko)\
**Post date:** [September 14, 2022, 3:04pm UTC](https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686/3 "2022-09-14T15:04:37Z")

</div>

Thanks @MutedJam for your quick answer but maybe you didn’t get my question or I asked a little bit imprecise. I would like to refer the first node variable inside the filtering operation of JMESPath. So something like this:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/f/4/f49d531cb7a5d56f4e328935b8e25e05a2625daa.png)

Obviously, is the expression inside the second quotation marks wrong but is there a possiblity to do this somehow or do I have to use the Function node?

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [September 15, 2022, 8:08am UTC](https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686/4 "2022-09-15T08:08:40Z")

</div>

Got it @Batijko, sorry for the misunderstanding. I couldn’t get this to work in the Set node/using the expression editor, presumably as the underlying library is somewhat limited.

It did, however, work fine when using the Function or [Function Item](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.functionitem) node using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) this like so:

The relvant code snippet is this one:

```javascript
item.result_expression = $jmespath($json.data, `[?email=='${$node["Dynamic mail"].json["mail"]}'].link | [0]`);

```

Result:

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/d/3/d347765554abcf4e92a48f1a925989f3e85912e7.png)

Is this what you had in mind?

---

<div class="post-metadata">

**Author:** ![Batijko](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/batijko/32/17185_2.png) [@Batijko](https://community.n8n.io/u/Batijko)\
**Post date:** [September 15, 2022, 8:50am UTC](https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686/5 "2022-09-15T08:50:36Z")

</div>

Yes, that’s exactly what I wanted. Solved it already with a simple JS forEach function but your solution looks pretty easy as well. Thanks a lot for the help @MutedJam 👍

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [September 15, 2022, 9:00am UTC](https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686/6 "2022-09-15T09:00:16Z")

</div>

Sweet, glad to hear you figured it out! Tbh, most of the time I also prefer plain JS over JMES path 😉

---

<div class="post-metadata">

**Author:** ![Batijko](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/batijko/32/17185_2.png) [@Batijko](https://community.n8n.io/u/Batijko)\
**Post date:** [September 22, 2022, 2:39pm UTC](https://community.n8n.io/t/filtering-with-a-value-from-a-previous-node/17686/7 "2022-09-22T14:39:00Z")

</div>

Hey @MutedJam I would have a small follow up question, if you could be so kind and help me out once again. I was playing around with JMESpath a little bit more and in the following workflow I have a small issue:

In the result node apart from _item.result\_dynamic\_id_ I’m getting all the correctly filtered results. My guess would be that I have to set the right quotation marks because changing the ones inside _item.result\_hardcoded_ gives me an empty result as well. I tried all possible combinations without a success. Any idea how the correct expression has to be here to get a result?
