cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
livingstonep
Kudo Kingpin
Kudo Kingpin

MS Flow expression: How to format calculated SharePoint field to 2 decimal places

we have a calculated column in our SharePoint List with the below formula:

 

=TEXT([Contract Value (£)]/(DATEDIF([Contract Start Date],[Contract End Date],"M")/12),"#,###.00")

here are the settings:

Calculated Field Format 3.PNG

 

In the list, it looks correct:

Calculated Field Format 1.PNG

Now in our Flow, we need to update a field in the list with a concatenated string using the below formula:

 

concat('The Annual Contract Value (£',triggerBody()?['AnnualContractValue'],') falls below the £50,000 annual threshold, so Finance & Procurement Approval was skipped')

this is then used in an email, but the value returned by the concatenated formula is incorrect:

Calculated Field Format 5.PNG

 

what we want to see is £1621.62

 

How can we format that currency number returned by the calculated field to 2 decimal places?

1 ACCEPTED SOLUTION

Accepted Solutions
gamoraes
Memorable Member
Memorable Member

Hi @livingstonep 

 

Unfortunately there isn't still an easy way to do this in Flow, however I've made a formula to work around this,

I show this here, but the formula to 'cut' this extra numbers is above, when the '2' in red are the amount of decimals to keep, and the ',' are the separator

 

 

substring(triggerBody()?['AnnualContractValue'],0,add(indexof(triggerBody()?['AnnualContractValue'],','),2))

 

addapted to your code the full expression is

 

concat('The Annual Contract Value (£',substring(triggerBody()?['AnnualContractValue'],0,add(indexof(triggerBody()?['AnnualContractValue'],','),2)),') falls below the £50,000 annual threshold, so Finance & Procurement Approval was skipped')

 

If my answer was helpful give me a kudo, if I answered question do not forget to mark as an answer to help the community

 


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


View solution in original post

4 REPLIES 4
gamoraes
Memorable Member
Memorable Member

Hi @livingstonep 

 

Unfortunately there isn't still an easy way to do this in Flow, however I've made a formula to work around this,

I show this here, but the formula to 'cut' this extra numbers is above, when the '2' in red are the amount of decimals to keep, and the ',' are the separator

 

 

substring(triggerBody()?['AnnualContractValue'],0,add(indexof(triggerBody()?['AnnualContractValue'],','),2))

 

addapted to your code the full expression is

 

concat('The Annual Contract Value (£',substring(triggerBody()?['AnnualContractValue'],0,add(indexof(triggerBody()?['AnnualContractValue'],','),2)),') falls below the £50,000 annual threshold, so Finance & Procurement Approval was skipped')

 

If my answer was helpful give me a kudo, if I answered question do not forget to mark as an answer to help the community

 


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


thanks for your answer, but what do you mean by separator?

 

concat('The Annual Contract Value (£',substring(triggerBody()?['AnnualContractValue'],0,add(indexof(triggerBody()?['AnnualContractValue'],','),2)),') falls below the £50,000 annual threshold, so Finance & Procurement Approval was skipped')

surely the sperator in my number is the decimal point ?

 

thanks for your help with this.

efialttes
Super User
Super User

@livingstonep 

Let's assume you obtain details of your list item via a Get Item action Block, so the output value of the column is

body('Get_item')?['YourColumnName']

 

I guess you don't want to modify the existing formula on your Sharepoint List, right? In such a case, I would suggest to use an WDL function based expression:

 

lastIndexOf() returns the starting position or index value for the last occurrence of a substring. This function is not case-sensitive, and indexes start with the number 0. You can use '.' as substring:

lastIndexOf(body('Get_item')?['YourColumnName'],'.')

 

add(): You can use it to calculate the lenght of the substring you need to extract in order to get the number with two decimals.

add(lastIndexOf(body('Get_item')?['YourColumnName'],'.'),1)

 

substring() returns characters from a string, starting from the specified position, or index. Index values start with the number 0. You can use 0 as startIndex, and the length of the substring you need to extract in order to get the number with two decimals.

 

substring(body('Get_item')?['YourColumnName'],0,

add(lastIndexOf(body('Get_item')?['YourColumnName'],'.'),1))

 

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Yes! is your decimal point, because in some cultures is '.' and others ','.

 

The function works?


Did I answer your question? Mark my post as a solution!

Gustavo Moraes, o astronauta brasileiro do Flow!


Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,488)