我想要一個 pass_fail 列,並且@tx尼爾森使它成為腳本。
但是,t如果許多列中的任何一個中間沒有規範,那麼他的腳本就不起作用。
我該如何修復它?
Names Default To Here( 1 );
dtOrig = current data table();
colNamesList = dtOrig << get column names( continuous, string );
// Create a work table of just the continuous columns
dt = dtOrig << subset( columns( colNamesList ), selected rows( 0 ) );
// Loop across all of the columns and apply a Range Check to eliminate
// all data outside of the upper and lower spec limits
For( theCol = 1, theCol <= N Items( colNamesList ), theCol++,
specs = Column( dt, colNamesList[theCol] ) << get property( "spec limits" );
Eval(
Substitute(
Expr(
Column( dt, colNamesList[theCol] ) << set property(
"Range Check",
(LELE( __LSL__, __USL__ ))
)
),
Expr( __LSL__ ), specs["LSL"],
Expr( __USL__ ), specs["USL"]
)
);
// Now convert the column to numeric
Column( dt, colNamesList[theCol] ) << data type( character );
// Now find all cells where values were eliminated
dt << select where( As Column( dt, colNamesList[theCol] ) == "" );
// If non passing rows were found, process the column to change the passing rows to
// a blank, and non passing to the name of the column
If( N Rows( dt << get selected rows ) > 0,
// Now set all eliminated cells to have the value of the name of the column
Column( dt, colNamesList[theCol] )[dt << get selected rows] = Column( dt, colNamesList[theCol] ) <<
get name;
// Invert the row selection, to select all rows where values passed and set them to a blank
dt << invert row selection;
Column( dt, colNamesList[theCol] )[dt << get selected rows] = "";
, // else set all
Column( dt, colNamesList[theCol] )[Index( 1, N Rows( dt ) )] = ""
);
);
// Now create a new column to hold the information on either that the row Passed or
// which columns failed
dt << New Column( "Pass_Fail", Character );
// Loop across all rows and set the values for the new column
For( theRow = 1, theRow <= N Rows( dt ), theRow++,
If( Trim( Concat Items( dt[theRow, 0, ""] ) ) == "",
:Pass_Fail[theRow] = "Pass"
,
thePass_Fail = Concat Items( dt[theRow, 0], "," );
For( i = Length( thePass_Fail ), i >= 2, i--,
If( Substr( thePass_Fail, i, 1 ) == ",",
If( Substr( thePass_Fail, i - 1, 1 ) == ",",
thePass_Fail = Substr( thePass_Fail, 1, i - 1 ) || Substr( thePass_Fail, i + 1 )
)
)
);
If( Right( thePass_Fail, 1) == ",", thePass_Fail = Left( thePass_Fail, length( thePass_Fail ) - 1 ) );
:Pass_Fail[theRow] = thePass_Fail;
)
);
// Only the new column is what is needed, so delete all other columns
dt << delete columns( eval(colNamesList) );
// Add the new column to the original data table
dtOrig << Update(
With( dt )
);
// Delete the no longer needed work table
close(dt, nosave );
我需要感謝@Byron_JMP用於回應。我本來打算回應這個討論,但在我這樣做之前,它轉移到了較舊的頁面,因此它從我的記憶中消失了。拜倫的回應將討論帶回了我的命名空間。
我相信要解決您的問題,您所要做的就是驗證給定的列是否具有與其相關的規格限制。並且,如果未找到規格限制,則不要處理該列。下面是一個有點神秘的建議更改,可能會滿足您的需求。問題的基本原理是使用 If() 函數僅在找到規範限制時處理代碼這是當前規範 = 代碼行的替換
clear symbols(specs);
specs = Column( dt, colNamesList[theCol] ) << get property( "spec limits" );
If(isEmpty(specs)==0,
<ALL of="" the="" code="" to="" the="" end="" of="" the="" for="" loop=""></ALL>
我喜歡簡單,就像我一樣!
所以我簡化了它(不需要嵌套):
If( :Data >= 42, "Too High", :Data < 7, "Too Low", "Just Right")
TXnelson 寫出了非常棒的代碼!
但是,也許您正在尋找一個簡單的解決方案,例如:
If( :Data >= 42,"Too High",If( :Data < 7,"Too Low","Just Right"))

這只是一個嵌套的 If 語句,如果數據值為 42 或更高,則公式返回“Too High”,如果數據小於 7,則返回“Too Low”,如果數據既不太高也不太低,則公式返回“Just Right”
您可以將公式粘貼到公式編輯器中,然後替換為正確的列名稱、值和消息。 (右鍵單擊列名稱,單擊公式,然後將上面的 JSL 粘貼到對話框中)
乾杯,
乙