SOLVED

SharePoint Online Date calculation with JSON

%3CLINGO-SUB%20id%3D%22lingo-sub-1505072%22%20slang%3D%22en-US%22%3ESharePoint%20Online%20Date%20calculation%20with%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1505072%22%20slang%3D%22en-US%22%3E%3CP%3Eis%20there%20a%20way%20to%20calculate%20a%20date%20value%20in%20a%20column%20based%20upon%20the%20entered%20date%20in%20one%20column%20plus%20a%20duration%20entered%20in%20another%20column%2C%20e.g.%20I%20am%20recording%20a%20purchase%20date%20on%20an%20item%20and%20its%20warranty%20period%20in%20years%20and%20I%20want%20to%20calculate%20the%20expiry%20date.%20I%20know%20I%20can%20do%20this%20in%20SharePoint%20calculated%20column%20but%20the%20value%20returned%20is%20in%20a%20text%20format%20not%20in%20a%20true%20date%20format%20so%20it%20is%20not%20easily%20usable%20in%20powerapps%20and%20power%20automate.%20I%20just%20wondered%20if%20JSON%20would%20return%20a%20v%20true%20'date%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1505072%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1505322%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20calculation%20with%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1505322%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F679719%22%20target%3D%22_blank%22%3E%40JamesMWood%3C%2FA%3E%26nbsp%3Byou%20can%20do%20this%20with%20a%20simple%20flow%20in%20Power%20Automate.%20The%20columns%20are%20StartDate%20(%3CEM%3EDateTime%3C%2FEM%3E)%2C%20WarrantyYears(%3CEM%3ENumber%3C%2FEM%3E)%20and%20WarrantyExpiryDate%20(%3CEM%3EDateTime).%26nbsp%3B%3C%2FEM%3EWhen%20an%20item%20is%20created%20or%20modified%20in%20your%20SharePoint%20list%20we%20calculate%20the%20number%20of%20warranty%20days%20(years%20x%20365)%2C%20convert%20that%20to%20an%20integer%20and%20then%20add%20those%20days%20to%20the%20start%20date.%20Finally%20we%20update%20the%20SharePoint%20item%20with%20the%20warranty%20expiry%20date%3A%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%22Flow1.png%22%20style%3D%22width%3A%20585px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F203545i322FC794FD217F85%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Flow1.png%22%20alt%3D%22Flow1.png%22%20%2F%3E%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%22Flow2.png%22%20style%3D%22width%3A%20593px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F203546i781A594CC9DDDE33%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Flow2.png%22%20alt%3D%22Flow2.png%22%20%2F%3E%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%22Flow3-SP-List.png%22%20style%3D%22width%3A%20713px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F203544i292C7EACC6962532%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Flow3-SP-List.png%22%20alt%3D%22Flow3-SP-List.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3BI%20always%20like%20to%20split%20up%20my%20Compose%20controls%20so%20that%20it's%20easy%20to%20see%20what%20each%20one%20is%20doing%2C%20but%20you%20could%20combine%20them%20if%20you%20wished%20to.%20The%20expressions%20in%20each%20Compose%20are%20shown%20in%20the%20comments.%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%22warranty.gif%22%20style%3D%22width%3A%20600px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F203547iEB3C5CAF6E3BA3BC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22warranty.gif%22%20alt%3D%22warranty.gif%22%20%2F%3E%3C%2FSPAN%3E%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%23333399%22%3EMicrosoft%20Power%20Automate%20Community%20Super%20User%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1508336%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20calculation%20with%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1508336%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F174092%22%20target%3D%22_blank%22%3E%40Rob%20Elliott%3C%2FA%3E%26nbsp%3BHi%20Rob%2C%20I%20have%20used%20the%20Compose%20options%20that%20you%20provided%20and%20when%20I%20updated%20the%20entry%20to%20test%20the%20flow%20I%20got%20the%20following%20error%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3EInvalidTemplate%3C%2FSTRONG%3E%3CSPAN%3E.%26nbsp%3BUnable%20to%20process%20template%20language%20expressions%20in%20action%20'ComposeWarrantyDays'%20inputs%20at%20line%20'1'%20and%20column%20'14067'%3A%20'The%20template%20language%20function%20'mul'%20expects%20its%20first%20parameter%20to%20be%20an%20integer%20or%20a%20decimal%20number.%20The%20provided%20value%20is%20of%20type%20'Null'.%20Please%20see%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Flogicexpressions%23mul%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Faka.ms%2Flogicexpressions%23mul%3C%2FA%3E%20for%20usage%20details.'.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1508360%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20calculation%20with%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1508360%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F679719%22%20target%3D%22_blank%22%3E%40JamesMWood%3C%2FA%3E%26nbsp%3Bthat%20indicates%20you've%20got%20no%20value%20in%20the%20Warranty%20period%20for%20one%20of%20the%20items%20in%20your%20list.%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%23333399%22%3EMicrosoft%20Power%20Automate%20Community%20Super%20User%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1509952%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20calculation%20with%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1509952%22%20slang%3D%22en-US%22%3EHi%20Rob%20that%20was%20what%20I%20able%20to%20decipher%20but%20when%20I%20checked%20the%20list%20all%20items%20have%20a%20value%20for%20the%20warranty%20period%2C%20I've%20looked%20at%20the%20column%20formatting%20as%20well%20and%20I%20cannot%20see%20any%20issues%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1520792%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20calculation%20with%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1520792%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F174092%22%20target%3D%22_blank%22%3E%40Rob%20Elliott%3C%2FA%3E%26nbsp%3BI%20had%20to%20recreate%20the%20warranty%20period%20column%20from%20scratch%20and%20the%20first%202%20compose%20actions%20work%2C%20I%20am%20now%20getting%20and%20error%20on%20the%203rd%20function%20with%20the%20following%20error.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnable%20to%20process%20template%20language%20expressions%20in%20action%20'ComposeAddDays'%20inputs%20at%20line%20'1'%20and%20column%20'13924'%3A%20'The%20template%20language%20function%20'addDays'%20expects%20its%20first%20parameter%20to%20be%20a%20string%20that%20contains%20the%20time.%20The%20provided%20value%20is%20of%20type%20'Null'.%20Please%20see%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Flogicexpressions%23adddays%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Faka.ms%2Flogicexpressions%23adddays%3C%2FA%3E%20for%20usage%20details.'.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20changed%20the%20format%20on%20the%20purchase%20date%20column%20to%20be%20date%20and%20time%20from%20date%20only%2C%20would%20you%20recommend%20re-doing%20the%20purchase%20date%20column%20from%20scratch%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESorry%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1521079%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20calculation%20with%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1521079%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F174092%22%20target%3D%22_blank%22%3E%40Rob%20Elliott%3C%2FA%3E%26nbsp%3BI%20think%20I%20have%20worked%20out%20what%20is%20going%20on.%20Although%20I%20am%20not%20sure%20why%20it%20is%20causing%20issues%20the%20SharePoint%20list%20was%20originally%20an%20excel%20file%20with%20all%20of%20the%20same%20columns%2C%20which%20I%20imported%20into%20sharepoint%20using%20the%20app%20to%20create%20a%20list%20from%20an%20excel.%20As%20soon%20as%20I%20create%20the%20date%20and%20duration%20columns%20in%20SharePoint%20the%20calculations%20work%2C%20I%20am%20not%20sure%20why%20but%20I%20assume%20that%20the%20import%20app%20has%20brought%20in%20some%20weird%20formatting%20from%20excel.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20I%20can%20happily%20report%20that%20your%20solution%20works%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1828892%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20Online%20Date%20calculation%20with%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1828892%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20can%20use%20toLocaleDateString()%20function%2Foperator%20in%20Column%20formatting%20to%20convert%20your%20date%20in%20friendly%20format.%3C%2FP%3E%3CP%3EAccording%20to%20official%20documentation%2C%3C%2FP%3E%3CP%3EtoLocaleDateString()%3A%20returns%20a%20language%20sensitive%20representation%20of%20just%20the%20date%20portion%20of%20a%20date%3C%2FP%3E%3CP%3E%22txtContent%22%3A%22%3DtoLocaleDateString(%40now)%22%20---%26gt%3B%20results%20vary%20based%20on%20user's%20locale%2C%20but%20en-us%20looks%20like%20%222%2F5%2F2019%22%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

is there a way to calculate a date value in a column based upon the entered date in one column plus a duration entered in another column, e.g. I am recording a purchase date on an item and its warranty period in years and I want to calculate the expiry date. I know I can do this in SharePoint calculated column but the value returned is in a text format not in a true date format so it is not easily usable in powerapps and power automate. I just wondered if JSON would return a v true 'date

7 Replies
Best Response confirmed by JamesMWood (Occasional Contributor)
Solution

Hi @JamesMWood you can do this with a simple flow in Power Automate. The columns are StartDate (DateTime), WarrantyYears(Number) and WarrantyExpiryDate (DateTime). When an item is created or modified in your SharePoint list we calculate the number of warranty days (years x 365), convert that to an integer and then add those days to the start date. Finally we update the SharePoint item with the warranty expiry date:

 

Flow1.png

 

Flow2.png

 

Flow3-SP-List.png

 

 I always like to split up my Compose controls so that it's easy to see what each one is doing, but you could combine them if you wished to. The expressions in each Compose are shown in the comments.

 

warranty.gif

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

@RobElliott Hi Rob, I have used the Compose options that you provided and when I updated the entry to test the flow I got the following error:

InvalidTemplate. Unable to process template language expressions in action 'ComposeWarrantyDays' inputs at line '1' and column '14067': 'The template language function 'mul' expects its first parameter to be an integer or a decimal number. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#mul for usage details.'.

 

 

@JamesMWood that indicates you've got no value in the Warranty period for one of the items in your list.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

Hi Rob that was what I able to decipher but when I checked the list all items have a value for the warranty period, I've looked at the column formatting as well and I cannot see any issues

@RobElliott I had to recreate the warranty period column from scratch and the first 2 compose actions work, I am now getting and error on the 3rd function with the following error.

 

Unable to process template language expressions in action 'ComposeAddDays' inputs at line '1' and column '13924': 'The template language function 'addDays' expects its first parameter to be a string that contains the time. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#adddays for usage details.'.

 

I have changed the format on the purchase date column to be date and time from date only, would you recommend re-doing the purchase date column from scratch?

 

Many thanks

 

 

Sorry

@RobElliott I think I have worked out what is going on. Although I am not sure why it is causing issues the SharePoint list was originally an excel file with all of the same columns, which I imported into sharepoint using the app to create a list from an excel. As soon as I create the date and duration columns in SharePoint the calculations work, I am not sure why but I assume that the import app has brought in some weird formatting from excel.

 

So I can happily report that your solution works

You can use toLocaleDateString() function/operator in Column formatting to convert your date in friendly format.

According to official documentation,

toLocaleDateString(): returns a language sensitive representation of just the date portion of a date

"txtContent":"=toLocaleDateString(@now)" ---> results vary based on user's locale, but en-us looks like "2/5/2019"