大家好
我曾經這樣做過一次,這很痛苦,但我失去了劇本和記憶。 下面是我正在嘗試做的事情:
Tweak_List = dt_Temp << 獲取列名稱("String");
for(i = 1, i <= N 項(Tweak_List),i++,
a = 左(Tweak_List[i], 長度(Tweak_List[i]) - 1) || “Δ”;
b = Tweak_List[i];
c = 左(Tweak_List[i], 長度(Tweak_List[i]) - 2);
dt << 新列( 左(Tweak_List[i], 長度(Tweak_List[i]) - 1) || "Δ", 數字, 連續, 公式( if(:name1 == :name2, c - b, 0 ))));
);
在 dt 中,我有名為 ColName_2 和 ColName 的列,Tweak_List 是 ColName_2 等列的名稱列表。
我需要創建一個名為 ColName_ 的新增量列Δ對於每一對,公式 ColName - ColName_2 表示滿足條件。
我記得我曾與 Eval 和 Co 一起工作,但我忘了。 請幫助我
和往常一樣,我終於找到了一個解決方案,可以自由地使用更高效的腳本重播。
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
)
)
)
)
);
);
您可以使用 Word() 或 Words() 代替 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, "_"))))
));
));
);
另外,如果您不需要公式而只需要值,您可以使用 << Set Each Value ,它不需要大量評估
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, "_"))
));
);