Jump to content
Salesforce and other SMB Solutions are coming soon. ×

Recommended Posts

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!

Link to comment
Share on other sites

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 by doughemi
Link to comment
Share on other sites

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
)

Link to comment
Share on other sites

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.

 

 

httpatomoreillycomsourceoreillyimages45289.png

Link to comment
Share on other sites

This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

Terms of Use