Ciao a tutti
L'ho fatto una volta, ed è stato doloroso, ma ho perso la sceneggiatura e il ricordo di quello. Di seguito quello che sto cercando di fare:
Tweak_List = dt_Temp << Ottieni nomi colonne("Stringa");
for(i = 1, i <= N elementi(Tweak_List),i++,
a = Left(Tweak_List[i], Length(Tweak_List[i]) - 1) || "Δ";
b = Tweak_List[i];
c = Left(Tweak_List[i], Length(Tweak_List[i]) - 2);
dt << Nuova colonna( Left(Tweak_List[i], Length(Tweak_List[i]) - 1) || "Δ", Numeric, Continuous, Formula( if(:name1 == :name2, c - b, 0 ))));
);
In dt ho colonne denominate ColName_2 e ColName, Tweak_List è l'elenco dei nomi di colonne come ColName_2.
Devo creare una nuova colonna Delta denominata ColName_ D per ogni coppia e avere la formula ColName - ColName_2 è una condizione soddisfatta.
Ricordo che stavo lavorando con Eval and Co, ma me ne sono dimenticato. Per favore aiutami
E come al solito, finalmente ho ottenuto una soluzione, sono libero di ripetere con uno script più efficiente.
For(i = 1, i <= N Items(Tweak_List), i++,
Eval(
Eval Expr(
dt << New Column(Left(Tweak_List[i], Length(Tweak_List[i]) - 1) || "Δ",
Numeric,
"Continuous",
Formula(
If(:ENTITY == :ENTITY_2,
As Column(Expr(Char(Left(Tweak_List[i], Length(Tweak_List[i]) - 2)))) - As Column(Expr(Char(Tweak_List[i]))),
0
)
)
)
)
);
);
Potresti usare Word() o Words() invece di Left().
Names Default To Here(1);
dt = New Table("Untitled 143",
Add Rows(1),
Compress File When Saved(1),
New Column("Column1", Numeric, "Continuous", Format("Best", 12), Set Values([1])),
New Column("Column1_2", Numeric, "Continuous", Format("Best", 12), Set Values([2])),
New Column("Column2", Numeric, "Continuous", Format("Best", 12), Set Values([3])),
New Column("Column2_2", Numeric, "Continuous", Format("Best", 12), Set Values([4]))
);
tweaklist = {"Column1_2", "Column2_2"};
For Each({col_name}, tweaklist,
Eval(EvalExpr(
dt << New Column(Word(1, col_name, "_") || "_Δ", Numeric, Continuous, Formula(
Expr(Name Expr(As Column(col_name))) - Expr(Name Expr(As Column(Word(1, col_name, "_"))))
));
));
);
Inoltre, se non hai bisogno della formula ma solo dei valori, puoi usare << Imposta ogni valore che non necessita di una valutazione pesante
For Each({col_name}, tweaklist,
dt << New Column(Word(1, col_name, "_") || "_Δ", Numeric, Continuous, << Set Each Value(
As Column(col_name) - As Column(Word(1, col_name, "_"))
));
);