많은 양의 데이터에 대한 백분율 차이 계산
안녕하세요 여러분!
이 게시물 아래에 예제 파일을 첨부했습니다.
현재 차이의 백분율을 계산하려고 합니다.
(New Value-Original Value)/Original Value로 주어진다.
이 경우 시간 0을 기준(원래 값)으로 합니다.
예를 들어:
시간: 0, 부품: 1 값 1: 690.2
시간: 50, 부품:1, 값1: 690.52
(690.52-690.2)/(690.2) = 0.046%
시간: 100, 부품:1, 값1:689.25
(689.25-690.2)/(690.2)= -0.13%
내가 얻고자 하는 결과는 Time, id, Part가 변경되지 않은 새 테이블을 갖는 것입니다.
백분율 형식의 값 1 및 값 2의 새 값을 갖는 동안.
다른 시간 값을 다른 테이블로 옮기는 것을 생각했습니다.
그런 다음 시간 0에 대해 계산하고 새 테이블에 추가하지만 단서가 없습니다.
스크립트에 작성하는 방법.
"Percentage Different Progress" 파일에 일부 스크립트를 작성했지만 막혔습니다.
누군가가 나를 도울 수 있다면 정말 감사하겠습니다.
미리 감사드립니다.

Re: 많은 양의 데이터에 대한 백분율 차이 계산정말 고마워 짐!Re: 많은 양의 데이터에 대한 백분율 차이 계산값 2 결과는 값 1 결과를 쉽게 대체할 수 있습니다.
아니요, 모든 열에 대해 JSL을 하드 코딩할 필요는 없습니다.데이터 테이블에 있는 만큼 많은 열에서 이 작업을 실행하는 방법을 설명하기 위해 이전 코드를 확장했습니다.또한 Time=0 행에 대해 원래 Value1 데이터가 변경되는 것을 원하지 않는다고 가정했지만, 그렇지 않은 경우 해당 결정을 내리는 If() 문을 제거하면 됩니다.
Names Default To Here( 1 );
dt = Current Data Table();
// Create a subset with only the data where Time = 0
dt2 = dt << subset( Rows( dt << get rows where( :Time == 0 ) ), selected columns( 0 ) );
// Delete the Time column. In the join step below, it
// will write on top of the original Time column if
// it remains in the subsetted data table
dt2 << delete columns( "Time" );
// Create a list of the column names so all of them can be
// changed to a new name for the Join below. Eliminate
// the columns "id" and "Part" from the name change since
// they will be used in the column matching in the Join.
divisorColNames = dt2 << get column names( string );
For( i = N Items( divisorColNames ), i >= 1, i--,
If( divisorColNames[i] == "id" | divisorColNames[i] == "Part",
divisorColNames = Remove( divisorColNames, i, 1 )
)
);
// Rename all of the divisor columns by "adding divisor_"
// in front of each name
For( i = 1, i <= N Items( divisorColNames ), i++,
Column( dt2, divisorColNames[i] ) << set name(
"divisor_" || Char( Column( dt2, divisorColNames[i] ) << get name )
)
);
// Join the data tables. All of the matching id and part
// values will be joined to all rows with the same values
dtJoin = dt << Join(
With( dt2 ),
Merge Same Name Columns,
Match Flag( 0 ),
By Matching Columns( :id = :id, :Part = :Part ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve main table order( 1 )
);
// The dt2 data table is no longer needed so close it
Close( dt2, nosave );
// Loop through all of the columns and create the new values
// unless the Time value is 0
For( theCol = 1, theCol <= N Items( divisorColNames ), theCol++,
For( theRow = 1, theRow <= N Rows( dtJoin ), theRow++,
If( dtJoin:Time[theRow] != 0,
Column( dtJoin, divisorColNames[theCol] )[theRow] = (
Column( dtJoin, divisorColNames[theCol] )[theRow]
-Column( dtJoin, "divisor_" || divisorColNames[theCol] )[theRow]) /
Column( dtJoin, "divisor_" || divisorColNames[theCol] )[theRow]
)
)
);
// Delete all of the no longer needed divisor columns
For( i = 1, i <= N Items( divisorColNames ), i++,
dtJoin << delete columns( "divisor_" || divisorColNames[i] )
);
Re: 많은 양의 데이터에 대한 백분율 차이 계산안녕 짐!
도움을 주셔서 감사합니다.
방법이 있는지 궁금합니다
1) 열 값 1 초기 셀에서 Value2(결과)를 교체합니다.
2) 실제로 이 작업을 수행하는 데 필요한 열(예: 30개)이 더 있는 경우(백분율 차이),
모든 새 열을 하드코딩해야 합니까, 아니면 열 생성을 곱하거나 반복할 수 있는 방법이 있습니까?
Re: 많은 양의 데이터에 대한 백분율 차이 계산원하는 것을 이해한다면 이것이 원하는 작업을 수행하는 가장 간단한 방법이라고 생각합니다.
dt = Current Data Table();
dt2 = dt << subset(
Rows( dt << get rows where( Time == 0 ) ),
columns( {"id", "Part", "Value1"} )
);
dt2:Value1 << set name( "divisor" );
dtJoin = dt << Join(
With( dt2 ),
Merge Same Name Columns,
Match Flag( 0 ),
By Matching Columns( :id = :id, :Part = :Part ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 0 ),
Preserve main table order( 1 )
);
Close( dt2, nosave );
dtJoin << New Column( "Value2",
Numeric,
"Continuous",
Format( "Percent", 10, 4 ),
Formula( (:Value1 - :divisor) / :divisor )
);
dtJoin:Value2 << delete property( "formula" );
dtJoin << delete columns( "divisor" );