Converting an absolute number into a range in Make (e.g., 13 → “5–25”)

:bullseye: What is your goal?

I’m trying to take an numeric value (for example, a company size of 12 coming from an API) and convert it into a predefined range label like “5–25”, “25–50”, etc, so I can map it into a dropdown/enum field that only accepts those range values. I’d ideally like to handle this with as few steps as possible and avoid creating multiple router paths for each individual range

:thinking: What is the problem?

When I use if() or switch() expressions inside Set Variable or directly in mapping fields, the expressions either get stored as plain text instead of being computed, or the output ends up blank, and I don’t want to avoid creating 8 different routes to fix this, unless it’s the only solution

:test_tube: What have you tried so far?

Building nested if() expressions in Set Variable to map the number into a range
Using switch() expressions for the same logic
Forcing conversion with toNumber()
Using Text Parser to extract the numeric value and then applying the range logic
Trying both Set Variable and Set Multiple Variables modules

:camera_with_flash: Screenshots: scenario setup, module configuration, errors

your formula looks fine but wrap the company size in toNumber() since make sometimes treats api numbers as text. make sure you’re mapping the variable output not the formula itself to your next module. if its still blank the receiving field probably doesnt accept dynamic values so youd need a router instead.

1 Like

Hey there,

your formula is just free text and not the actual formula. Select the if() function from the menu to see the difference. Same for the less than or equal to operator. You might also need to place the variable inside a parseNumber() functuon to convert it to a number type variable for math functions.

The formula is definitely not fine - its just free text and not a formula at all; and there is no toNumber() in Make, its parseNumber(). Please don’t use AI to generate responses here.

Hello, a potential good idea is to use a router module, you mentioned that you need to select from a specific dropdown. You won’t need to set a variable but use the “Company Size” output as the evaluation criteria.

Add a Router Module

Then add the number of routes you will need, in this case it is seven

Then for each of your routes click on the filter icon connecting them and set the criteria that will make that route true.

Finally continue mapping the modules in each path with the condition that is true. You can hard code this or simply select the dropdown depending on the app module you are connecting.

I hope this helps.

Hello,

Your function is not properly encoded. You are using plain text as operators.

This is how your function should look like:

You can copy and paste this code into your mapping field:

{{if(9.companySize < 1; "Empty"; if(9.companySize <= 5; "1-5"; if(9.companySize <= 25; "5-25"; if(9.companySize <= 50; "25-50"; if(9.companySize <= 100; "50-100"; if(9.companySize <= 500; "100-500"; if(9.companySize <= 1000; "500-1000"; "1000+")))))))}}

Just remember to adjust the mapping so it points to the correct 9.Company Size.

Please let me know if that solves your issue!

Have a nice day!

1 Like

Welcome to the Make community!

You can also do this with a switch module instead, which could make it easier to change the options in future.

Here’s an example.

and here are some test cases:

Module Subflow Export - paste modules into your scenario

You can copy and paste this into the scenario editor. This will import the example modules shown in my screenshots above.

{"subflows":[{"flow":[{"id":162,"module":"util:Switcher","version":1,"parameters":{},"mapper":{"input":"88","useRegExpMatch":true,"casesTable":[{"pattern":"^[1-5]$","output":"1-5"},{"pattern":"^([5-9]|1\\d|2[0-5])$","output":"5-25"},{"pattern":"^([2-4]\\d|50)$","output":"25-50"},{"pattern":"^([5-9]\\d|100)$","output":"50-100"},{"pattern":"^([1-4]\\d\\d|500)$","output":"100-500"},{"pattern":"^([5-9]\\d\\d|1000)$","output":"500-1000"},{"pattern":"^[1-9]\\d+$","output":"1000+"}],"elseOutput":"{{null}}"},"metadata":{"designer":{"x":3433,"y":-1798,"messages":[{"category":"last","severity":"warning","message":"A transformer should not be the last module in the route."}]}}}]}],"metadata":{"version":1}}
Need help❓View instructions ◀

1. Move your mouse over the line of code above.
Copy the JSON by clicking the copy button on the right-side:

2. Enter your scenario editor. Close any open panels by pressing ESC. Press CTRLV (paste keyboard shortcut for Windows) to paste directly in the editor.

3. Click on imported modules and re-save it to trigger validation. There may be some errors prompting you to re-map some variables and select connections.

Note: Did you know you can also reduce the size of blueprint exports and module subflows like the above, using my Make Blueprint Scrubber?

Hope this helps! If you are still having trouble, please provide more details.

@samliew
P.S.: investing some effort into the tutorials in the Make Academy will save you lots of time and frustration using Make!