差距和孤岛:入学差距,评估第一记录

Gaps and Islands: gap in enrollment, evaluate first record

数据:

'student#'  'enrollment date'  'removal date'   
1       1/1/2014        1/4/2015    
1       1/15/2015       null
2       1/1/2015        1/4/2015
...

我想证明注册失败了。并创建了下面的公式,它适用于除第一条记录以外的所有记录。 :) :(

有没有办法评估不存在的东西?

// records must be sorted by add date descending [newest to oldest]
//cant seem to evaluate anything previous to the first record
//0.01 means currently enrolled [made to chk logic]
//0.02 means no gap [made to chk logic]

if 
not isnull ({REM_DATE}) and
previous ({STUDENT_ID}) <> {STUDENT_ID}
then today - {REM_DATE}

else if 
isnull ({REM_DATE}) 
then 0.01

else if 
previous ({StudentID}) = {StudentID} and
previous ({ADD_DATE}) > {REM_DATE}
then previous ({ADD_DATE}) - {REM_DATE}

else 0.02

解决方法:

// for below formula to work data must be sorted first by studentID then by enrollment date [descending]



//provision for first record and not receiving services measures gap from today
if
not isnull ({table.REM_DATE}) and
onfirstrecord 
then today - {table.REM_DATE}

//currently not receiving services measures gap from today
else if 
not isnull ({table.REM_DATE}) and
previous ({table.STUDENT_ID}) <> {STUDENT_ID}
then today - {table.REM_DATE}

//currently enrolled
else if 
isnull ({table.REM_DATE}) 
then 0.01

// measures gap in enrollment
else if 
previous ({table.STUDENT_ID}) = {table.STUDENT_ID} and
previous ({table.ADD_DATE}) > {table.REM_DATE}
then previous ({table.ADD_DATE}) - {table.REM_DATE}

//no gap in service
else
0.02