Help combining SharePoint formula statements - DATEIF and ISERROR
-
19-02-2021 - |
Question
I am running a SharePoint formula that calculates the length of time (in yrs, months, and days) before a project expires.
In the "Will Expire" column the following formula is running:
=DATEDIF(CurrentDate,[End Date],"Y")&" Years "&DATEDIF(CurrentDate,[End Date],"YM")&" Months "&DATEDIF(CurrentDate,[End Date],"MD")&" Days"
The "CurrentDate" column is updated daily as part of a Power Automate job. The "End Date" column is manually added as part of the project term.
For expired projects, a result is a negative number which is an error with DATEIF that shows up as #NUM!.
I do not want negative numbers to show and used DATEDIF to get an error in hopes of changing the error to something more user friendly.
However when adding an ISERROR statement - I cannot get the syntax of the combined statements to work.
Any help or ideas to use a better way appreciated.
La solution
To avoid #NUM!
, you should use ISERROR
as below
=IF(ISERROR(DATEDIF(CurrentDate,[End Date],"Y")),"show error message",DATEDIF(CurrentDate,[End Date],"Y"))
To match this with your formula, the final formula with ISERROR
should like
=CONCATENATE(IF(ISERROR(DATEDIF(CurrentDate,[End Date],"Y")),"0",DATEDIF(CurrentDate,[End Date],"Y"))," Years ",IF(ISERROR(DATEDIF(CurrentDate,[End Date],"YM")),"0",DATEDIF(CurrentDate,[End Date],"YM"))," Months",IF(ISERROR(DATEDIF(CurrentDate,[End Date],"MD")),"0",DATEDIF(CurrentDate,[End Date],"MD"))," Days")
Output
On error for all conditions, it should show
0 Years 0 Months 0 Days
ISERROR
returnstrue
if there is an error. so that in the If clause. if there is an error, it will show your preferred statement. otherwise, it would calculate the DATEDIF. Read also Supported and Unsupported Columns in SharePoint Calculated Column Formula