Skip to main content

Calculation formula within variable input


A_Gussenberg

Hey folks, first of all I love the new variable function. Within the setup of spacings I want to reference my base value (“8”) and do calculations, e.g. (spacing-base)*2". This works fine and the value is calculated properly within the input to add a new variable. But I expected not that the calculation string changes to the absolute value. With this behaviour I loose the connection/ reference to my base value and the calculation is some how obsolete.

Does anybody feel the same?
Will there be an update?

image

Thanks

62 replies

Daniel_Myrenne

I would appretiate this feature as well!
Scaling items depending on values is one thing I’m working most of the times.


Nomad_Bakr

Yeah, It would be great to add calc() function to variables definitions similar to CSS including numbers, colors, and booleans


It will be great to be able to create REM.


Josh_Mitchell

My eCommerce prototype contains 3 prices that change based on the user’s choices: monthly price, total price and RRP. Each of these prices is set to a variable, which updates based on the interaction.

Currently to update the 3 prices each choice has to trigger 3 conditions (e.g. if user chooses option A then ‘Total price’=100, ‘Monthly price’=‘Total price’ ÷ 12 and ‘RRP’=‘Total price’ + 10.

It would save a lot of time if I could set these relations in the variables values themselves (e.g. ‘Monthly price’=Total price ÷ 12 and ‘RRP’=‘Total price’ + 10). This would mean that each choice would only need to update the ‘Total price’ and the ‘Monthly price’ and ‘RRP’ would update automatically.


Johan_Wastring

I am looking forward to this as well. It would be super handy and save a lot of time when rescaling things if you could use the variables on things like corner radii.


Jared_Rice

+1 being able to multiply spacing values by a base variable would save a lot of manual effort


Dave_Tanner

+1 for this. Need this for things like base values and REM, and would also be handy for proportional resizing.


Flowmedia

+1
I would like to change radius, and inner radiuses based on a single number. (Mainradius-2)


+1 Would love this feature as well!


Jenni_Merrifield

+1 from me for defining one variable as the result of a calculation of one or more other variables.

I would also like the ability to apply calculations anywhere a variable can be assigned. Essentially, the flip side to assigning calculations to variable definitions is that instead of requiring multiple variables, one for each calculation, you could have a few base variables and then specify any calculation using them where you need to.

For example, if you have two layers, X & Y, which need to have opposite visibility (i.e. if one is shown/hidden, the other is hidden/shown) I could create Boolean “x-is-visible”, and then apply “x-is-visible” to X and “not x-is-visible” to Y. Otherwise you’d need two variables to accomplish the same thing.


Bohdan24
  • 1 reply
  • January 31, 2024

+1 Need this feature to be able to create easy customisable design system


mo_hamwi
  • New Participant
  • 49 replies
  • January 31, 2024

+1 I agree


Toby_Magrath1

+1000 we def need this asap. I am trying to set up a pretty large library that will be shared across many lines of business, they all have and want different things like spacing, padding, and corners plus we want to add controls for density which a multiplier would be perfect for e.g. #base-spacing*1.5


Robert_Wiese

+1 for this. Very nice feature to have 👍


Tim_Judemann

+1 from me, too


Anke_M
  • 1 reply
  • April 12, 2024

+1 one more vote for this!!!


To actually properly support measurement tokens, this is essential.


  • 1 reply
  • April 17, 2024

+1 one more vote for this.


Sanny
  • New Member
  • 25 replies
  • April 19, 2024

any status on this feature?


Bonnie_Mercer

Would love this feature also!!


This really is a key feature to enable scalable design systems. Would be super grateful if this could be added.


Dave_Curtis

When creating variables, it would be really useful to be able to include maths and text when defining a variable, which are kept up-to-date based on current values.

E.g.
With a shopping basket, I have the following variable
• Subtotal# (numeric)
Into which I add the value of each product selected in the basket.

From this value I would like to calculate
• VAT# (numeric) = Subtotal * 20%, truncated to 2 decimal places

And then display these variables in a currency
• Subtotal£ (String) = “£” + Subtotal#
• VAT£ (String) = “£” + VAT#
• Total£ (# String) = “£” + Subtotal#+VAT#

This way, I could just add/remove the product costs from Subtotal#, and use the strings for display in the prototype.


neelts
  • 10 replies
  • May 12, 2024

Hi @Dave_Curtis, my new plugin does exactly what you want, give it a try!
https://www.figma.com/community/plugin/1365339609215368041/dynamic-variables

Here’s the list of your expressions, but with the syntax of my plugin,
just paste these {{ }} expressions into the description fields of the corresponding variables and run the plugin Dynamic Variables → Start Monitoring Changes or Dynamic Variables → Update Once:

• VAT# (numeric) = {{ $Subtotal * .2 }}
• Subtotal£ (String) = {{ "£" + ( $Subtotal ).toFixed(2) }}
• VAT£ (String) = {{ "£" + ( $VAT ).toFixed(2) }}
• Total£ (# String) = {{ "£" + ( $Subtotal + $VAT ).toFixed(2) }}

Hope this helps!


neelts
  • 10 replies
  • May 12, 2024

And here’s the video showing how the plugin works in action based on your request:


neelts
  • 10 replies
  • May 12, 2024

Hey @A_Gussenberg, I just wanted to let you know that my new plugin Dynamic Variables does exactly what you’re looking for!
Here’s a quick video to show you how it works:

https://www.figma.com/community/plugin/1365339609215368041/dynamic-variables

@Josh_Mitchell your request is super close to this one, I posted video there too:

Let me know if you have any questions!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings