Hi Ivan
I would like share what I did with your help:
formula
switch (rowIndex())
{
case 1:
var_TotalInitial=column("Vlr_Total_Saldo");
var_qtd_prev_row = 0
column("Vlr_Total_Saldo");
break;
default:
var calc0=column("@TotalSTRetidoItemFinal")+column("@TotalSTDesta+OPItemFinal")
var calc1=(column("@CFOP_Ficha3") === "1409") ? calc0:0; // site link "Ternary expressions"
var_qtd_prev_row = column("qt_saldo_aggreg",-1)
if (column("@CFOP_Ficha3") == "1409")
{var_TotalInitial = var_TotalInitial + calc1}
else if (column("@CFOP_Ficha3") == "1411")
{var_TotalInitial = isNaN(roundHalfUp((var_TotalInitial / var_qtd_prev_row) * column("qt_saldo_aggreg"),2)) ? 0: (roundHalfUp((var_TotalInitial / var_qtd_prev_row) * column("qt_saldo_aggreg"),2)) }
else if (column("@CFOP_Ficha3") == "5927")
{var_TotalInitial = roundHalfUp((var_TotalInitial / var_qtd_prev_row) * column("qt_saldo_aggreg"),2) }
else if (column("@CFOP_Ficha3") == "5405")
{var_TotalInitial = roundHalfUp((var_TotalInitial / var_qtd_prev_row) * column("qt_saldo_aggreg"),2) }
else if (column("@CFOP_Ficha3") == "5119")
{var_TotalInitial = roundHalfUp((var_TotalInitial / var_qtd_prev_row) * column("qt_saldo_aggreg"),2) }
else if (column("@CFOP_Ficha3") == "5409")
{var_TotalInitial = roundHalfUp((var_TotalInitial / var_qtd_prev_row) * column("qt_saldo_aggreg"),2) }
else if (column("@CFOP_Ficha3") == "5209")
{var_TotalInitial = roundHalfUp((var_TotalInitial / var_qtd_prev_row) * column("qt_saldo_aggreg"),2) }
//vTotalInitial = vTotalInitial + rule1
//https://stackoverflow.com/questions/31971801/setting-a-javascript-variable-with-an-if-statement-should-the-var-x-be-in
}
See that I used the switch case as you taught me (formula above)
Regarding the offset column, I incorporated it into the calculation with a variable (var_qtd_prev_row). And with that, within the if or else if, I included the rule inside.
It was a way to learn as well.
Now, I would like to migrate this entire formula to the Java Snippet and see if our friend, takk, could help me.
In other words, I want to replicate exactly the result I achieved in the “column expressions” in the Java Snippet so that I can understand how it works.
Yesterday, I tried to do it myself, but I couldn’t include the variables.
Actually, right from the start, with the row index, the rule is not the same.
For example, in the column expression, the rule for the row index is simple, just type rowindex().
But it seems to me that the Java Snippet is totally different.
Later, I will open a new topic, set up the flow, and notify takk to see if he can simulate it for me and recreate it in Java. It will be a way for me to learn and it becomes easier when it’s a subject I’m familiar with.
In another topic, @ArjenEX helped me with a question I asked about whether it’s possible to fill two columns at the same time using the same variable as output, and in Java Snippet it’s possible. I found it very interesting. But learning Java is complex, there are different concepts.
But anyway, what you taught me about the switch changed everything for me. I will use it a lot.
There must be so much more to learn with “column expressions” still.