How do you "get" the filter value?

Hey there,
I have a filter set up after a module. Let’s say the filter lets through 18 items from the previous module, how do I “get” the number 18 and use it as a variable?

The use case: I want to count the number of items in a Webflow CMS collection that matches a given criteria.

Many thanks
Jacob

Hi @Jacob1 there are different ways to achieve this, if the resultant bundle is an array, you can use the length() function. Can you share a screenshot of the filtered result/bundle?

Hi there, thanks for reaching out,
Here are two screenshots. In this case I want to add the number 41 in column B of my Google Sheet.


I wouldn’t try to do this by counting each individual matching item. That could burn a lot of Make operations.

The Webflow List Items module is iterating over every Webflow item that matches the parameters.

I would explore the possibility of then using an aggregator to create a single array of all your Webflow items, and then using the map() function to create an array that contains only the collections that match the criteria you’re currently filtering for.

Then, to find out how many match you’d simply use the length() function to count the number of entries in the new array.

The result would look something like this (NB - I’ve not tested this so you may need to make further tweaks!):

1 Like

As @DavidGurr_Make suggested you could use an array aggregator just after the filter, this will return an output bundle called “_IMTAGGLENGTH” which contains the count of the filtered items

output of array aggregator

after then, you can use an iterator to get back all items so you can iterate through on to google sheet

sample result

then you can further use this variable as you choose to

1 Like

@Emmanuel_Momoh I like your solution better!

As is usual with Make, there’s many ways of cracking the same problem.

1 Like

Hey again, many thanks for your input.
I started with trying @DavidGurr_Make 's solution, and it worked like a charm. See below.

Just a related question: What if I’m filtering for an amount (I am), and I’d like to summarize all the 41 amounts into a total. Any idea how I can achieve this?

Thanks again, very helpful,

When you say “summarize”, do you mean the total of all amounts of the matching items?

Yes exactly, let’s say I want to use the value 30,000 below.

Matching item #1: $10,000
Matching item #2: $10,000
Matching item #3: $10,000
Total: $30,000 < --------

For that, you’d use the sum() function which sums the values in a simple array.

You’d first need to create that simple array that contains just the values you’re interested in. If, for example, the value element in the Field Data array is called value, then this should do it:
sum(map(2.Array[] ; fieldData ; value))

Hi again, and thank you so much -
I’ll post this as a new thread if it helps. BUT… I found another way (perhaps less efficient) to summarize the values. Now I’m stuck sorting them and listing the top three…

Can you please advise me what modules to use at the end?

I’ve tried using a sort function in “set multiple variables”, but they simply don’t sort. Is that the way to do it?


Cheers
Jacob

Hi Jacob.

I don’t think you need the Iterator or the Numeric Aggregator.

If I understand correctly, there’s three results you want:

  • The number of Chapter 11 events - provided by the length() function
  • The total value of Chapter 11 event assets - provided by the sum() function
  • An array with the top three Chapter 11 events by ordered by asset value

For the sum, you just need to use the function I posted previously, with 2.Array[] referencing your own array that gets output by the Array Aggregator. The value field will be the short name you see when you hover over Tillgånger SEK.

The same input array can be used for the length() function and the sum() function - there’s no need to iterate it again.

For the top three Chapter 11 events, you should be able to get that array using this function:
slice(sort(2.Array[] ; desc; value) ; 0 ; 2)

2.Array[] is the same source array as used in the length() and sum() functions.
value is the same Tillgånger SEK short name.

See Array Functions in the Make help for details on all those functions.

Once you have that array of the top 3 Chapter 11 events you can iterate over it however you like - if you’re aiming to produce textual output listing them, use a Text Aggregator.

Edit: After posting the below I’m staring to think that there’s an issue with nesting the slice and sort function. I can make this work if I run the sort function in one module and the slice function in the next.

Hi again David,
Ok, so I get the two first steps to work. The last step (slice and sort) I can’t get to work for some reason. I’m not a coder, so I may get something wrong here?


It looks like you’re missing a semicolon in the slice/sort expression to separate the arguments - there should be one before the zero.

1 Like

Thank you so much David, all the pieces fell into place now. I really appreciate your help – this forum is such a wonderful resource!

2 Likes