如何從另一列的相同分組值的 if 語句中擴展行選擇? 如果附加文件第 7 行被選擇為:
dt << select where (:D1 > 1);
選擇應擴展到 G1 列中的所有分組值,在這種情況下都是“B”
我要求公式列,因為數據是由 SQL 更新的。 帶有索引號的現有公式列正在根據新數據自動更新。
我不確定你想用公式版本做什麼。也就是說,您期望什麼值最終會出現在新列中,但下面是我對您可能想要做什麼的猜測。
僅供參考,公式版本的效率不如腳本版本,因為它必須為每一行執行一次。
If( Row() == 1,
dt = Current Data Table();
d1Rows = dt << get rows where( :D1 > 1 );
g1Values = {};
If( N Rows( d1Rows ) > 0,
For( i = 1, i <= N Rows( d1Rows ), i++,
Insert Into( g1Values, dt:G1[d1Rows[i]] )
)
);
);
If( Contains( g1Values, :G1 ),
x = 1;
Row State( Row() ) = Selected State( 1 );
,
x = 0
);
x;
這是應用了公式的數據表腳本
New Table( "IfSelRows",
Add Rows( 15 ),
Compress File When Saved( 1 ),
New Column( "G1",
Character( 1 ),
"Nominal",
Set Values(
{"A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "C", "C", "C", "C",
"C"}
),
Set Display Width( 76 )
),
New Column( "D1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 0] ),
Set Display Width( 58 )
),
New Column( "Column 3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
If( Row() == 1,
dt = Current Data Table();
d1Rows = dt << get rows where( :D1 > 1 );
g1Values = {};
If( N Rows( d1Rows ) > 0,
For( i = 1, i <= N Rows( d1Rows ), i++,
Insert Into( g1Values, dt:G1[d1Rows[i]] )
)
);
);
If( Contains( g1Values, :G1 ),
x = 1;
Row State( Row() ) = Selected State( 1 );
,
x = 0
);
x;
)
)
)再次感謝代碼。 它按預期工作。 必須更改或添加到代碼中才能將其用作公式列?
@txnelson寫道:
您的問題有幾種不同的解釋,但我希望我要解決的問題是正確的。看看我的劇本,告訴我這是不是你在想的
Names Default To Here( 1 );
dt = New Table( "IfSelRows",
Add Rows( 15 ),
Compress File When Saved( 1 ),
New Column( "G1",
Character( 1 ),
"Nominal",
Set Values( {"A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C"} ),
Set Display Width( 76 )
),
New Column( "D1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 0] ),
Set Display Width( 58 )
)
);
// Get the rows where D1 > 1
d1Rows = dt << get rows where( :D1 > 1 );
// Create a list with the values of G1 for the rows that have been selected
g1Values = {};
If( N Rows( d1Rows ) > 0,
For( i = 1, i <= N Rows( d1Rows ), i++,
Insert Into( g1Values, dt:G1[d1Rows[i]] )
)
);
// Select the rows where any of the values in the g1List exist
dt << select where(contains(g1Values,:G1));再次感謝代碼。 它按預期工作。 必須更改或添加到代碼中才能將其用作公式?
感謝吉姆的快速回复。 你說對了我的問題。 您的腳本完全符合我的要求。
您的問題有幾種不同的解釋,但我希望我要解決的問題是正確的。看看我的劇本,告訴我這是不是你在想的
Names Default To Here( 1 );
dt = New Table( "IfSelRows",
Add Rows( 15 ),
Compress File When Saved( 1 ),
New Column( "G1",
Character( 1 ),
"Nominal",
Set Values( {"A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C"} ),
Set Display Width( 76 )
),
New Column( "D1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 0] ),
Set Display Width( 58 )
)
);
// Get the rows where D1 > 1
d1Rows = dt << get rows where( :D1 > 1 );
// Create a list with the values of G1 for the rows that have been selected
g1Values = {};
If( N Rows( d1Rows ) > 0,
For( i = 1, i <= N Rows( d1Rows ), i++,
Insert Into( g1Values, dt:G1[d1Rows[i]] )
)
);
// Select the rows where any of the values in the g1List exist
dt << select where(contains(g1Values,:G1));