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 😙

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
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.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022- Season 2 has kicked off!

Users online (4,768)