고리? 여러 열과 분석 (날짜)간에 이름을 변경하는 열 이름으로 작업에서 누락 된 데이터를 계산합니다.이 커뮤니티가 도움이 되었으면하는 질문이 있습니다. 마지막 날에서 누락 된 연속 날짜를 보여주는 열을 추가하고 싶습니다.
또한 7 개 열에서 결과가 0.02보다 높은 날을 세는 열을 추가하고 싶습니다.
일련의 if 문을 사용하여 두 가지 모두에 대한 해결책을 찾았지만 루프를 사용하여 더 우아한 방법으로 수행 할 수 있는지 배우고 싶습니다.
마지막으로 테이블의 날짜가 매주 변경되므로이 수식이 열 이름과 독립적이기를 바랍니다. 이것이 가능한가?
내 솔루션과 함께 비슷한 모양의 데이터 테이블을 첨부했습니다.
미리 감사드립니다
/ Markku
스크립팅Re : 루프? 여러 열과 분석 (날짜)간에 이름을 변경하는 열 이름으로 작업에서 누락 된 데이터를 계산합니다.여기 제가 생각 해낸 대체 공식이 있습니다.
If( Row() == 1,
start = 2;
end = 8;
);
count = end;
While( Is Missing( Column( count )[Row()] ) == 1 & count >= start, count-- );
end - count;
Re : 루프? 여러 열과 분석 (날짜)간에 이름을 변경하는 열 이름으로 작업에서 누락 된 데이터를 계산합니다.내 솔루션은 필요한 것보다 약간 더 복잡 할 가능성이 높습니다 (example_new 테이블 생성과 함께 첨부 된 전체 스크립트). 이 솔루션은 관심있는 열의 이름이 "Max (something")으로 지정 될 것으로 예상합니다 (7 개 이상의 "Max ("열이있는 경우에도 작동해야 함).
이러한 두 수식 열은 데이터 변경시 다시 계산하는 기능을 잃게되며 데이터 테이블에서 데이터가 변경되면 빨간색 삼각형 테이블에서 "수동으로"다시 실행해야합니다.

열에 대한 공식 :
//modified idea based on of @txnelson solution
tempCol = dt << New Column("# last days missing_community", Numeric, Nominal,
Formula(
Local({
//get information on column names
dt = Current Data Table(),
colNames = dt << Get Column Names(String)
},
//get list of column names with only Max( in name
For(i = N Items(colNames), i > 0, i--,
If(!Contains(colNames[i], "Max("),
Remove From(colNames, i);
)
);
//get values on rows
//this might make a mistake if columns before Max( have are missing values
matLength = N Items(colNames) + 1;
rowValues = dt[Row(), 0][1::matLength];
count = 0;
//calculate missing values from the end of matrix and stop on first found value
While(Is Missing(rowValues[matLength]), count++; matLength--);
count;
)
)
);
dt << New Column("#days higher than 0,02_community", Numeric, Nominal,
Formula(
Local({
//get information on column names
dt = Current Data Table(),
colNames = dt << Get Column Names(String)
},
//get values on row and set values of colums without Max( in name to 0
rowVals = dt[Row(), 0];
For(i = N Items(colNames), i > 0, i--,
If(!Contains(colNames[i], "Max("),
rowVals[i] = 0;
)
);
//create matrix with 0 and 1 based on if value is over 0.02
rowVals_over = rowVals > 0.02;
//get sum of previous matris to calculate Max( columns with values over 0.02
Sum(rowVals_over);
);
)
);
Re : 루프? 여러 열과 분석 (날짜)간에 이름을 변경하는 열 이름으로 작업에서 누락 된 데이터를 계산합니다.소중한 @Markku ,
또한 동적 스크립트를 만들고 열 수식으로 구문 분석하는 데 어려움을 겪고 있습니다. 과거에 나는 당신과 비슷한 상황이 있었는데, 반복되는 측정 (당신의 경우에는 매일 반복되는 배치)의 수가 하나의 관측 (배치)에서 다른 관측으로 바뀔 수있었습니다.
내 솔루션은 귀하의 필요에 따라 약간 거칠어 보일 수 있지만 작동해야한다고 생각합니다.
사용하기 전에 가질 수있는 다른 시나리오에 대해 강력한 지 확인하십시오.
데이터 테이블을 연 상태에서이 스크립트를 실행하고 결과를 검사하십시오.
Names Default To Here( 1 );
dt = Current Data Table();
// get list of columns
Cols = dt << get column names ( Continuous );
maxlist = {};
For( i = 1, i <= N Items( cols ), i++,
If( Contains( cols[i], "Max" ),
Insert Into( maxlist, cols[i] )
)
);
dt2 = dt << Stack(
columns(maxlist ),
Source Label Column( "Time" ),
Stacked Data Column( "Data" )
);
dt2 << Sort(
By( :Batch#, :Time ),
Order( Ascending, Descending ),
replace table
);
dt2 <<NEW column=""> :Index2 ) << delete rows ();
dt3 = dt2 << Summary(
Group( :Batch# ),
Freq( "None" ),
Weight( "None" ),
Link to original data table( 0 ),
);
close (dt2, no save);
dt3:N Rows << set name ("No of last days missing");
dt << new column ("No of last days missing", set each value (0));
dt << Update(
With( dt3 ),
Match Columns( :Batch# = :Batch# )
);
close (dt3, no save);
//
dt5 = dt << Stack(
columns(maxlist ),
Source Label Column( "Time" ),
Stacked Data Column( "Data" )
);
dt5 << select where (ismissing (:Data)) << delete rows;
dt5 << select where (:Data<=0.02) << delete rows;
dt6 = dt5 << Summary(
Group( :Batch# ),
Freq( "None" ),
Weight( "None" ),
Link to original data table( 0 )
);
close (dt5, no save);
dt6:N Rows << set name ("Days over 0.02");
dt << new column("Days over 0.02", set each value(0));
dt<< Update(
With( dt6 ),
Match Columns( :Batch# = :Batch# )
);
close (dt6, no save);
<BR /></NEW>
작동하는지 알려주세요.
Ron