I have some variables that need other variables to output the correct data. But I cannot figure this out, because for the first variable, I need something that will be calculated later in my code.
Since you have 3 variables and 3 equations, you could use substitution.
If you substitute the 2nd equation into the 3rd, and the 3rd into the 1st, you could rewrite it like this:
{% assign var1 = (16,84/17,05)*isoc %}
Please let me know if my calculations are correct.
Okay, so the same thing, but a little bit more complicated then
So this works in Excel because it approximates the values through an iterative calculation which bypasses the circular reference problem from your example.
Unfortunately this is not possible in Liquid and as you’ve noticed, you can’t calculate with variables that are assigned further down in your code.
So I’m afraid the only option you’re left with is basic algebra. Again by substitution you can rewrite your Var3 & Var4 statements so they’re no longer referring to variables further down.
This is what I’ve worked out:
This is working, but I think it will be too complex because the code is not finished yet. For example, var3 is a bit more complex that I wrote here and sometimes in var7 0.25 can be 0.20 and so on…
Unfortunately there’s nothing you can do in Liquid to get around the circular references in your variable assignments. The only solution is to rewrite your assignments so there no longer referring to variables that are assigned further down (which themselves refer to variables higher up). Even though the equations are more complex or have more variables, you could still use substitution to resolve this issue.