SP List - Dates using IF AND formula

%3CLINGO-SUB%20id%3D%22lingo-sub-1233652%22%20slang%3D%22en-US%22%3ESP%20List%20-%20Dates%20using%20IF%20AND%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1233652%22%20slang%3D%22en-US%22%3E%3CP%3EWorking%20on%20an%20attendance%20tracker%20and%20can't%20quite%20get%20a%20formula%20to%20work%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20Out%20of%20PTO%20%3D%20Yes%20and%20the%20date%20is%20before%2010%2F1%2F2020%2C%20I%20need%20a%20roll-off%20date%20to%20be%2012%2F31%2F2020.%26nbsp%3B%20If%20the%20date%20is%20after%2010%2F1%2F2020%20but%20before%2012%2F31%2F2020%2C%20then%20I%20need%20the%20roll-off%20date%20to%20be%20the%20Attendance%20date%20plus%2090%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20what%20I%20have%20so%20far%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DIF(AND(%5BOut%20of%20PTO%3F%5D%3D%22Yes%22%2CDate%26gt%3B%3D10%2F1%2F2020)%2CDate%2B90%2C1%2F1%2F2021)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20only%20gives%20me%20date%20%2B%2090%2C%20even%20when%20I%20put%20in%20a%203%2F20%2F2020%20date%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1233652%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELists%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1236172%22%20slang%3D%22en-US%22%3ERe%3A%20SP%20List%20-%20Dates%20using%20IF%20AND%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1236172%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Bryan%20(%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F325149%22%20target%3D%22_blank%22%3E%40Bryan123%3C%2FA%3E%26nbsp%3B)%2C%20trying%20to%20work%20out%20the%20correct%20formula%20gave%20me%20a%20headache%20so%20if%20you%20don't%20manage%20to%20find%20it%20you%20might%20want%20to%20consider%20an%20alternative%20method%20to%20calculate%20the%20date.%20And%20that%20method%20is%20to%20use%20a%20flow%20in%20Power%20Automate%20with%20conditions%20which%20will%20update%20the%20date%20calculation%20column%20with%20the%20relevant%20date%20when%20you%20press%20a%20button%20on%20the%20list%20item%20in%20SharePoint.%20It's%20not%20scary%20or%20difficult%20and%20it%20does%20do%20what%20you%20want%20it%20to%20do.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20our%20list%20I%20have%20a%20Yes%2FNo%20column%20for%20PTO%20and%20Date%20columns%20for%20the%20Attendance%20and%20CalcDate%20columns.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20the%20button%2C%20add%20a%20single%20line%20of%20text%20column%20and%20from%20the%20column%20header%20select%20Column%20setting%20then%20Format%20this%20column%20and%20paste%20in%20the%20following.%20You%20will%20later%20need%20to%20change%20the%20flow%20ID%20to%20your%20flow%20but%20the%20code%20to%20use%20is%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%22%2C%0A%20%20%22elmType%22%3A%20%22button%22%2C%0A%20%20%22txtContent%22%3A%20%22Calc%20Date%22%2C%0A%20%20%22customRowAction%22%3A%20%7B%0A%20%20%20%20%22action%22%3A%20%22executeFlow%22%2C%0A%20%20%20%20%22actionParams%22%3A%20%22%7B%5C%22id%5C%22%3A%20%5C%220529cdcd-5562-4643-a4d3-832b77a5fa25%5C%22%7D%22%0A%20%20%7D%2C%0A%20%20%22style%22%3A%20%7B%0A%20%20%20%20%22background-color%22%3A%20%22%23468259%22%2C%0A%20%20%20%20%22color%22%3A%20%22white%22%0A%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EThe%20section%20above%20after%20id%5C%22%3A%20%5C%22%26nbsp%3B%20is%20the%20ID%20you%20need%20to%20change.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%220-SP-list.png%22%20style%3D%22width%3A%20836px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F177863i7C6B9B5DFD73FB60%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%220-SP-list.png%22%20alt%3D%220-SP-list.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOK%20so%20for%20the%20flow%20go%20into%20Power%20Automate%20and%20in%20the%20My%20Flows%20screen%20click%20New%20and%20Instant%20from%20blank%20then%20click%20Skip%20so%20you%20start%20with%20a%20totally%20blank%20flow.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20trigger%20is%20a%20SharePoint%20%3CEM%3EFor%20a%20selected%20item%3C%2FEM%3E%20and%20you%20select%20your%20site%20and%20the%20list.%20The%20first%20action%20is%20to%20Get%20that%20item%20and%20the%20info%20in%20it.%20So%20add%20a%20SharePoint%20%3CEM%3EGet%20item%3C%2FEM%3E%20action.%20Again%2C%20select%20the%20site%20and%20list%20and%20select%26nbsp%3B%3CSTRONG%3EID%3C%2FSTRONG%3E%20from%20the%20dynamic%20content%20box%20that%20pops%20up%20when%20you%20click%20in%20the%20ID%20field.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20next%20action%20is%20to%20add%20a%20Condition%20that%20will%20check%20if%20the%20item%20in%20the%20PTO%20column%20equals%20Yes.%20Select%20the%20PTO%20column%20from%20the%20dynamic%20content%20for%20the%20left%20box.%20For%20the%20middle%20box%20select%20%3CSTRONG%3Eis%20equal%20to%3C%2FSTRONG%3E.%20For%20the%20right%20hand%20criteria%20box%20you%20need%20to%20enter%20%3CSTRONG%3Etrue%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%221-trigger-get-condition.png%22%20style%3D%22width%3A%20588px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F177865i119783762ABF158F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%221-trigger-get-condition.png%22%20alt%3D%221-trigger-get-condition.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIf%20the%20PTO%20column%20is%20NOT%20equal%20to%20Yes%20(true)%20then%20do%20nothing%2C%20so%20just%20leave%20the%20red%20If%20no%20channel%20empty.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%20in%20the%20If%20Yes%20green%20channel%20add%20another%20condition.%20Select%20the%20Attendance%20column%20for%20the%20left%20field.%20Select%20is%20less%20than%20for%20the%20middle%20field%20and%20enter%202020-10-1%20in%20the%20right%20field.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%222-condition2.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F177864i23801A644FA4D373%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%222-condition2.png%22%20alt%3D%222-condition2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20green%20If%20yes%20channel%20add%20a%20SharePoint%20Update%20item%20action%20and%20in%20the%26nbsp%3B%20CalDate%20column%20type%20in%202020-12-31.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20red%20If%20no%20column%20add%20another%20condition%20with%202%20rows.%20the%20first%20is%20if%20Attendance%20is%20greater%20than%20or%20equal%20to%202020-10-1.%20The%20second%20row%20is%20Attendance%20is%20less%20than%20or%20equal%20to%202020-12-31.%3C%2FP%3E%3CP%3ELeave%20the%20red%20If%20no%20channel%20empty.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20green%20If%20yes%20channel%20add%20a%20%3CEM%3ECompose%3C%2FEM%3E%20control%20and%20from%20the%20expression%20tab%20of%20the%20dynamic%20content%20copy%20%26amp%3B%20paste%20in%20the%20following%20expression%20to%20calculate%2090%20days%20from%20the%20Attendance%20date%20column%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSTRONG%3EaddDays(body('Get_item')%3F%5B'Attendance'%5D%2C90)%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EFinally%20below%20that%20add%20a%20SharePoint%20%3CEM%3EUpdate%20item%3C%2FEM%3E%20action.%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%223-update1-condition3-compose90.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F177866iA39DA3AA118FD881%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%223-update1-condition3-compose90.png%22%20alt%3D%223-update1-condition3-compose90.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EFor%20the%20CalcDate%20column%20%2C%20from%20the%20dynamic%20content%20select%20the%20output%20of%20the%20Compose%20action.%20That%20will%20add%20a%20date%2090%20days%20ahead%20of%20the%20Attendance%20column.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%224-update2.png%22%20style%3D%22width%3A%20963px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F177867iBD734D889A776CC3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%224-update2.png%22%20alt%3D%224-update2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20if%20you%20enter%202020-03-20%20in%20the%20Attendance%20column%20and%20click%20the%20button%2C%20that%20will%20enter%202020-12-31%20in%20to%20the%20CalcDate%20column.%20If%20you%20add%202020-12-03%20into%20the%20Attendance%20column%20and%20click%20the%20button%20that%20will%20add%202021-03-03%20into%20the%20CalcDate%20column.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20quite%20understand%20that%20it's%20not%20the%20solution%20you%20were%20asking%20for%20and%20is%20a%20route%20you%20might%20not%20want%20to%20go%20down%2C%20but%20maybe%20it%20will%20open%20up%20other%20opportunities%20for%20you%20that%20you%20might%20not%20have%20thought%20of.%20I%20hope%20it%20helps%20as%20a%20possible%20alternative.%20Come%20back%20with%20any%20questions%20about%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERob%3CBR%20%2F%3ELos%20Gallardos%3CBR%20%2F%3E%3CFONT%20size%3D%222%22%20color%3D%22%233366FF%22%3EMicrosoft%20Power%20Automate%20Community%20Super%20User%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

Working on an attendance tracker and can't quite get a formula to work

 

If Out of PTO = Yes and the date is before 10/1/2020, I need a roll-off date to be 12/31/2020.  If the date is after 10/1/2020 but before 12/31/2020, then I need the roll-off date to be the Attendance date plus 90

 

Here is what I have so far:

 

=IF(AND([Out of PTO?]="Yes",Date>=10/1/2020),Date+90,1/1/2021)

 

This only gives me date + 90, even when I put in a 3/20/2020 date

 

Any ideas?

1 Reply
Highlighted

Hi Bryan (@Bryan123 ), trying to work out the correct formula gave me a headache so if you don't manage to find it you might want to consider an alternative method to calculate the date. And that method is to use a flow in Power Automate with conditions which will update the date calculation column with the relevant date when you press a button on the list item in SharePoint. It's not scary or difficult and it does do what you want it to do. 

 

In our list I have a Yes/No column for PTO and Date columns for the Attendance and CalcDate columns.

 

For the button, add a single line of text column and from the column header select Column setting then Format this column and paste in the following. You will later need to change the flow ID to your flow but the code to use is:

 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "Calc Date",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\": \"0529cdcd-5562-4643-a4d3-832b77a5fa25\"}"
  },
  "style": {
    "background-color": "#468259",
    "color": "white"
  }
}

 


The section above after id\": \"  is the ID you need to change.

0-SP-list.png

 

OK so for the flow go into Power Automate and in the My Flows screen click New and Instant from blank then click Skip so you start with a totally blank flow.

 

The trigger is a SharePoint For a selected item and you select your site and the list. The first action is to Get that item and the info in it. So add a SharePoint Get item action. Again, select the site and list and select ID from the dynamic content box that pops up when you click in the ID field.

 

The next action is to add a Condition that will check if the item in the PTO column equals Yes. Select the PTO column from the dynamic content for the left box. For the middle box select is equal to. For the right hand criteria box you need to enter true.

 

1-trigger-get-condition.png

If the PTO column is NOT equal to Yes (true) then do nothing, so just leave the red If no channel empty.

 

However in the If Yes green channel add another condition. Select the Attendance column for the left field. Select is less than for the middle field and enter 2020-10-1 in the right field.

 

2-condition2.png

 

In the green If yes channel add a SharePoint Update item action and in the  CalDate column type in 2020-12-31.

 

In the red If no column add another condition with 2 rows. the first is if Attendance is greater than or equal to 2020-10-1. The second row is Attendance is less than or equal to 2020-12-31.

Leave the red If no channel empty.

 

In the green If yes channel add a Compose control and from the expression tab of the dynamic content copy & paste in the following expression to calculate 90 days from the Attendance date column:

addDays(body('Get_item')?['Attendance'],90)
 
Finally below that add a SharePoint Update item action. 
 

3-update1-condition3-compose90.png

 

For the CalcDate column , from the dynamic content select the output of the Compose action. That will add a date 90 days ahead of the Attendance column.

 

4-update2.png

 

So if you enter 2020-03-20 in the Attendance column and click the button, that will enter 2020-12-31 in to the CalcDate column. If you add 2020-12-03 into the Attendance column and click the button that will add 2021-03-03 into the CalcDate column.

 

I quite understand that it's not the solution you were asking for and is a route you might not want to go down, but maybe it will open up other opportunities for you that you might not have thought of. I hope it helps as a possible alternative. Come back with any questions about it.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User