创建新列并根据另一列(列名变量)设置不同列中的每一行值你好,

我有类似于图中示例的数据。前 6 列是相关的。我创建了 MaxCol 列,以便根据前 3 列找出谁拥有最大值,然后我想创建 MaxValFromCol 列,该列会从 4-6 列中的一列中取值。它会根据 MaxCol 从 4-6 列中取值。我尝试使用 Column(char(:MaxCol) || "_t") 设置 MaxValFromCol 的值,但没有成功。有人能提供一些建议吗?我们如何将列值作为列名,并基于它设置值?
自动化和脚本回复:创建新列并根据另一列(列名变量)从不同的列设置每一行的值这是我为 MaxCol 提出的公式
As Constant(
startCol = 1;
endCol = 3;
nCol = (endCol - startCol) + 1;
dt = Current Data Table();
colNames = dt << get column names;
);
theMax = Loc( dt[Row(), Index( startCol, endCol )], Max( dt[Row(), Index( startCol, endCol )] ) );
theMax = (theMax + startCol) - 1;
colNames[theMax][1];
这是 MaxValFromCol 的公式
As Constant(
startCol = 1;
endCol = 3;
nCol = (endCol - startCol) + 1;
dt = Current Data Table();
colNames = dt << get column names();
);
theMax = Loc( dt[Row(), Index( startCol, endCol )], Max( dt[Row(), Index( startCol, endCol )] ) )
+ncol;
Parse( Char( colNames[themax][1] ) );

现在已经很晚了,我相信其他人会有更好的解决方案。
回复:创建新列并根据另一列(列名变量)从不同的列设置每一行的值嗨,吉姆,
我能够获取 MaxCol 的值。我希望 MaxValFromCol 的值是第 4-6 列的值,而不是列名。例如,第 1 行 MaxCol =="Lily",那么 MaxValFromCol 的第 1 行将从 Lily_t 中获取值,即 4|5。第 2 行是 4|4,因为 MaxCol 的第 2 行是 Mike,所以 4|4 来自 Mike_t。

回复:创建新列并根据另一列(列名变量)从不同的列设置每一行的值对于只有几列的情况,我认为可以使用像下面这样的 if 条件,但我的列太多了。所以我想知道是否有办法使用 MaxCOl 值作为变量来调用该列。
如果只有几列,则以下方法可以奏效:
如果(:MaxCol ==“Lily”,:Lily_t,
:MaxCol =="Mike", :Mike_t,
:MaxCol =="Dan", :Dan_t,
)
当我有数百列时,希望有如下简单的东西
MaxValFromCol == 列(char(:MaxCol)||“ _t”)
回复:创建新列并根据另一列(列名变量)从不同的列设置每一行的值我的错误.......深夜......我会改正。
以下是我正在使用的两个公式

As Constant(
startCol = 1;
endCol = 3;
nCol = (endCol - startCol) + 1;
dt = Current Data Table();
colNames = dt << get column names( string );
);
theMax = Loc( dt[Row(), Index( startCol, endCol )], Max( dt[Row(), Index( startCol, endCol )] ) );
theMax = (theMax + startCol) - 1;
x = colNames[theMax][1];
x;
As Constant(
startCol = 1;
endCol = 3;
nCol = (endCol - startCol) + 1;
dt = Current Data Table();
colNames = dt << get column names( string );
);
theMax = Loc( dt[Row(), Index( startCol, endCol )], Max( dt[Row(), Index( startCol, endCol )] ) )
+ncol;
Eval( Parse( "x=:" || colNames[theMax][1] ) );
回复:创建新列并根据另一列(列名变量)从不同的列设置每一行的值我不太确定我是否会使用这样的东西,但它可能会有用
As Column(Column(:Column 1 ||"_t"))
您也很可能删除 Column()
As Column(:Column 1 || "_t")