web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Create file name with ...
Power Automate
Unanswered

Create file name with week number and attachment name

(0) ShareShare
ReportReport
Posted on by 26

I attempted to create a flow that triggers when a new email arrives. The flow checks specific criteria, such as file names and subject lines. If all criteria match, it proceeds to save the file in a designated SharePoint location. Everything is functioning correctly up to this point. Now, I aim to save the file with the week number and the actual received file name. For instance, if the attachment is named 'Data' and the mail was received on August 28, 2023, the file will be saved with the name 'Wk 35 Data'.

 

I attempted to achieve this using the following expression, but encountered an error:

 

"InvalidTemplate. Unable to process template language expressions in action 'Create_file' inputs at line '0' and column '0': 'The template language function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'.

 
Create file under sharepoint > *File Name >
concat('Wk-', add(div(sub(int(formatDateTime(outputs('Compose'), 'd')), int(formatDateTime('2023-01-01', 'd
Categories:
I have the same question (0)
  • annetoal Profile Picture
    1,934 Moderator on at

    Part of your expression seems to be missing. If it looks exactly like that in your Flow, that could be what's causing the error.

    According to Bing Chat, you can use this expression to calculate the number of the week. Then you could concatenate the output from the expression into your file-naming expression.

    add(div(dayOfYear(convertFromUtc('your_date_string','your_time_zone','yyyy')),7),1)
    

    You will have to insert your date string and time zone information in the indicated places in the expression. Give it a try and see how it works. 

  • JoelArchy Profile Picture
    5 on at

    Hi All,

    I tried the above formula and have attached my code below

     

    add(div(dayOfYear(convertFromUtc('2024-06-13T11:43:00.0000000Z','GMT Standard Time','yyyy')),7),1)

     

    I was hoping to pull through the date in the file name so I can keep track of the end-of-week reports. I'm currently getting the error: 

     

    InvalidTemplate

    Unable to process template language expressions in action 'Create_file' inputs at line '0' and column '0': 'In function 'dayOfYear', the value provided for date time string '2024' was not valid. The datetime string must match ISO 8601 format.'.
     
    I was wondering if anyone has any input.
     
    Joel

     

     

  • Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at

    Bing Chat 😂🤣

    If you need to consider time zones, remove the format string from Bing Chat's proposal.

     

    If not, just use this:

     

     

    add(
    	div(
    		dayOfYear(utcNow()),
    		7
    	),
    	1
    )

     

     

    Since there are several definitions of "week number", this might not meet your expectation.

  • Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at

    OK, a more serious answer:

    This flow should return the week number according to ISO 8601 using the algorithm provided in the article.

     

    Discalimer: Dates are a mess and writing date functions should be done by people who know more about the subject than I do 😉

     

    Chriddle_1-1718361911955.png

     

    Weeks(y)

     

     

    if(
    	or(
    		and(
    			equals(
    				mod(
    					int(formatDateTime(outputs('Date'), 'yyyy')),
    					4
    				),
    				0
    			),
    			not(
    				equals(
    					mod(
    						int(formatDateTime(outputs('Date'), 'yyyy')),
    						100
    					),
    					0
    				)
    			),
    			equals(
    				dayOfWeek(concat(formatDateTime(outputs('Date'), 'yyyy'), '-01-01')),
    				3
    			)
    		),
    		and(
    			not(
    				equals(
    					mod(
    						int(formatDateTime(outputs('Date'), 'yyyy')),
    						4
    					),
    					0
    				)
    			),
    			equals(
    				dayOfWeek(concat(formatDateTime(outputs('Date'), 'yyyy'), '-01-01')),
    				2
    			)
    		)
    	),
    	53,
    	52
    )

     

     

     

    Weeks(y-1)

     

     

    if(
    	or(
    		and(
    			equals(
    				mod(
    					sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),
    					4
    				),
    				0
    			),
    			not(
    				equals(
    					mod(
    						sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),
    						100
    					),
    					0
    				)
    			),
    			equals(
    				dayOfWeek(	
    					concat(
    						string(
    							sub(
    								int(formatDateTime(outputs('Date'), 'yyyy')),
    								1
    							)
    						),
    						'-01-01'
    					)
    				),
    				3
    			)
    		),
    		and(
    			not(
    				equals(
    					mod(
    						sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),
    						4
    					),
    					0
    				)
    			),
    			equals(
    				dayOfWeek(	
    					concat(
    						string(
    							sub(
    								int(formatDateTime(outputs('Date'), 'yyyy')),
    								1
    							)
    						),
    						'-01-01'
    					)
    				),
    				2
    			)
    		)
    	),
    	53,
    	52
    )

     

     

     

    W

     

     

    div(
    	add(
    		10,
    		sub(
    			dayOfYear(outputs('Date')),
    			if(
    				less(
    					dayOfWeek(outputs('Date')),
    					1
    				),
    				7,
    				dayOfWeek(outputs('Date'))
    			)
    		)
    	),
    	7
    )

     

     

     

    Woy

     

     

    if(
    	less(
    		outputs('W'),
    		1
    	),
    	outputs('Weeks(y-1)')
    	,
    	if(
    		greater(
    			outputs('W'),
    			outputs('Weeks(y)')
    		),
    		1,
    		outputs('W')
    	)
    )

     

     

    Chriddle_2-1718362105463.png

     

    I also combined all of the above to one big expression 😎

    if(less(div(add(10,sub(dayOfYear(outputs('Date')),if(less(dayOfWeek(outputs('Date')),1),7,dayOfWeek(outputs('Date'))))),7),1),if(or(and(equals(mod(sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),4),0),not(equals(mod(sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),100),0)),equals(dayOfWeek(concat(string(sub(int(formatDateTime(outputs('Date'), 'yyyy')),1)),'-01-01')),3)),and(not(equals(mod(sub(int(formatDateTime(outputs('Date'), 'yyyy')), 1),4),0)),equals(dayOfWeek(concat(string(sub(int(formatDateTime(outputs('Date'), 'yyyy')),1)),'-01-01')),2))),53,52),if(greater(div(add(10,sub(dayOfYear(outputs('Date')),if(less(dayOfWeek(outputs('Date')),1),7,dayOfWeek(outputs('Date'))))),7),if(or(and(equals(mod(int(formatDateTime(outputs('Date'), 'yyyy')),4),0),not(equals(mod(int(formatDateTime(outputs('Date'), 'yyyy')),100),0)),equals(dayOfWeek(concat(formatDateTime(outputs('Date'), 'yyyy'), '-01-01')),3)),and(not(equals(mod(int(formatDateTime(outputs('Date'), 'yyyy')),4),0)),equals(dayOfWeek(concat(formatDateTime(outputs('Date'), 'yyyy'), '-01-01')),2))),53,52)),1,div(add(10,sub(dayOfYear(outputs('Date')),if(less(dayOfWeek(outputs('Date')),1),7,dayOfWeek(outputs('Date'))))),7)))

    Great for a quiz: What does this expression do? 🤣

  • JoelArchy Profile Picture
    5 on at

    Hi Chriddle,

     

    Thanks for the help. I'll give this a try when I get the chance.

     

    Joel

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard