cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SpaSniper
Regular Visitor

FormatDateTime inside Apply to Each

Hi, I have the following SharePoint list:

1.png

With this SharePoint list I want to get a variable that increases each time the year of the column date is 2020. Therefore, in this case the variable would be equal 2.

My problem in the Flow:

2.png

In the Flow what I do inside the apply to each is a condition: FormatDateTime("COLUMN_DATE",'yyyy') equals to string('2020'). Where "COLUMN_DATE" is just the value of the Dynamic content of the column date from my SharePoint list. However, each time I run the Flow it gets only the first value of the year from the column that is 2019 and uses this value for all the apply to each. Why doesn't it loop the formatdatetime function through each value of the column date and only uses the first value?

 

Thank you so much for your answers and do not hesitate to ask me if some parts are not well explained.

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

Try it like this:

IncrementBasedOnYear.PNG

The code in the increment variable expression is like this:

if(equals(formatDateTime(items('Apply_to_each')?['Date'], 'yyyy'), '2020'), 1, 0)

Which just says if it is year 2020 then increment by 1, else 0.

 

Please...

If I answered your question Accept it as a solution ✔️ 

If I helped you out, please give me some Kudos 👍

Thanks 😙

View solution in original post

7 REPLIES 7
tom_riha
Super User
Super User

Hello @SpaSniper ,

I'd say you're not using dynamic content provided by the 'Apply to each' action, you're using the triggerOutputs() which is a fixed value in all the loops. The correct dynamic content should be something like 'items('Apply_to_each')?...', just use the output from the 'Apply to each' instead of output of the trigger action.



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ I also blog about Power Automate solutions even for non-IT people. ]

Hi, if I use the output of the current 'Apply to each', I get the following error. So I don't know what to use.

Unable to process template language expressions for action 'Condition' at line '1' and column '11611': 'The template language function 'formatDateTime' expects its first parameter to be of type string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#formatdatetime for usage details.'.


Paulie78
Super User
Super User

Try it like this:

IncrementBasedOnYear.PNG

The code in the increment variable expression is like this:

if(equals(formatDateTime(items('Apply_to_each')?['Date'], 'yyyy'), '2020'), 1, 0)

Which just says if it is year 2020 then increment by 1, else 0.

 

Please...

If I answered your question Accept it as a solution ✔️ 

If I helped you out, please give me some Kudos 👍

Thanks 😙

View solution in original post

I get the following error @Paulie78 😞

 

Unable to process template language expressions in action 'Increment_variable' inputs at line '1' and column '11613': 'The template language function 'formatDateTime' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#formatdatetime for usage details.'.


The expression I provided was:

if(equals(formatDateTime(items('Apply_to_each')?['Date'], 'yyyy'), '2020'), 1, 0)

You need to replace 'Date' with the name of your column that contains the date. If you want to troubleshoot, add a compose step with an expression of just:

items('Apply_to_each')?['Date']

(Again, replacing Date with the name of your column). This will enable you to see the value of the Date that is being manipulated. 

 

 

Yes I understood @Paulie78 , the thing is, the name of my column is Date. So when I put Date in the formula it gives me the error from above.

Okay, my mistake, I got the wrong title name for the column, it appears as 'Date' but it was something strange such as 'vdoh'. Thank you so much for your help!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (2,856)