mwade Posted December 21, 2015 Share Posted December 21, 2015 Hello, I need to be able to calculate how long someone stayed in a shelter based on the date they entered, the date they exited OR the date they moved in to housing. We currently have two separate fields that work just fine but I need to know how to combine the do using an OR condition. The current calculations are: LOS based on Exit date: If(IsEmpty(ExitDate);Get ( CurrentDate )-EntryDate ; ExitDate - EntryDate) LOS based on Move in date: If(IsEmpty(MoveinDate) and IsValid ( ExitDate );"--"; If(IsEmpty(MoveinDate);Get ( CurrentDate )-EntryDate ; MoveinDate - EntryDate)) Thank you! Quote Link to comment Share on other sites More sharing options...
doughemi Posted December 21, 2015 Share Posted December 21, 2015 (edited) This is best solved with a Case statement: XXXXXXXXXXXXXXXXX See Next Post XXXXXXXXXXXXXXX Case( IsEmpty(ExitDate); Get ( CurrentDate )-EntryDate; IsEmpty(MoveinDate); Get ( CurrentDate )-EntryDate; IsEmpty(MoveinDate) and IsValid ( ExitDate );"--"; isValid(ExitDate); ExitDate - EntryDate; MoveinDate - EntryDate ) Case() stops evaluating when it finds a True argument so the arguments had to move a bit (for example, if you just check for isValid(ExitDate) before you test for IsEmpty(MoveinDate), it'll never check for an empty MoveinDate). Always put the most restrictive arguments first. Edited December 22, 2015 by doughemi Quote Link to comment Share on other sites More sharing options...
doughemi Posted December 22, 2015 Share Posted December 22, 2015 Sheesh! I violated my own rule and didn't check for a valid Entry date before operating on an empty MoveInDate: Case( IsEmpty(ExitDate); Get ( CurrentDate )-EntryDate; IsEmpty(MoveinDate) and IsValid ( ExitDate );"--"; IsEmpty(MoveinDate); Get ( CurrentDate )-EntryDate; isValid(ExitDate); ExitDate - EntryDate; MoveinDate - EntryDate ) Quote Link to comment Share on other sites More sharing options...
AHunter3 Posted December 22, 2015 Share Posted December 22, 2015 Note also that you have to designate this as an unstored calculation field or it will not work correctly. That is true of any calculation field that utilizes Get(CurrentDate) or, for that matter, pretty much any Get function. If it is a STORED calc, it will glance around and assess the value of Get(CurrentDate) once, then store the result, then fail to update unless ExitDate, MoveinDate, or EntryDate are modified. It will not update at midnight when the day rolls over. An UNSTORED calc field will not hang on to a result and will reassess on-the-fly whenever you reference (or click into or display) the field. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.