Calculated field

Deleted
Not applicable

I'm looking to create a calculated field to achieve the following..

 

I have a date field  called  ExpiryDate   and I have a calculated Datefield  called CalcExpiryDate with the following syntax which works great =ItemDate+TermDays this returns a date and time value.

 

Some items will have an ExpiryDate and some won't, all will have a calculated date.  I want to create the following result; if ExpiryDate is blank then use the above calculation, if not use the ExpiryDate.. 

 

Was thinking could do this in 1 of 2 ways..   

  1. Extend the syntax in the existing calculated field to do the calculation in that field if possible
  2. Create an extra field called ActualExpiryDate which checks the other 2 and gives the result..

Can't seem to hit on the right syntax..

 

Any ideas?

1 Reply

I don't know if you can do this with a calculated column, but I would do it with a Power Apps customised form and do the logic there instead of using the default SharePoint form.

 

This is the SharePoint list and you can see that it achieves what you want. The ItemDate, ExpiryDate and CalcExpiryDate are all Date/Time columns. The TermsDays column is a number column:


0-SP-List.png

 

This is the customised Power Apps form (from the Power Apps menu above your list). I have renamed the datacards, labels and data fields so that they are understandable.

 

In the Default Date of the dataCalcExpiryDate you need to enter the following expression:
If(IsBlank(dataExpiryDate.SelectedDate), DateAdd(dataItemDate.SelectedDate,Value(dataTermDays.Text)), dataExpiryDate.SelectedDate)

which means that if the dataExpiryDate is blank then add the value in the dataTermDays field to the dataItemDate selected date, otherwise (i.e it's not blank) then use the selected date in the dataExpiryDate field.

 

1-CustomisedFormPA.png

 

2-Form.png

 

One gotcha: due to the way Power Apps handles null values in a datepicker (or rather it doesn't due to a programming oversight apparently) you need to turn on the experimental feature shown below. If you don't do this then if you delete the date in the dateExpiryDate field and save it won't delete it and will keep the previous value saved in the list.

 

99-ExperimentalFeatures.png

 

And you can see it in action on the attached video.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User