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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / String expression for ...
Power Automate
Unanswered

String expression for document naming

(0) ShareShare
ReportReport
Posted on by 4

Hello I am trying to write a string expression to name a document. Via power automate, I pull a list every month and save it in a library. The name of the document should be the previous month and the year. My issue is when the month is January. The name if the document should be December and the previous year. Can someone help me write an expression that says if January name if previous month and previous year anything else name if previous month and current year? 

Categories:
  • jinivthakkar Profile Picture
    4,187 on at

    @wubbs11 

     

    jinivthakkar_4-1613028453110.png

     

     

    jinivthakkar_1-1613028258454.png

     

    jinivthakkar_3-1613028356361.png

     

    jinivthakkar_0-1613028219622.png

     

    Output:

     

    jinivthakkar_5-1613028508016.png

     

    --------------------------------------------------------------------------------
    If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

  • jinivthakkar Profile Picture
    4,187 on at

    @wubbs11 Logic is as follows - I have initialized variable DtNow is set to UtcNow() but you need to set your dynamic value, I have then initialized two variable Month & Year. Then I get month & year value using expression

     

    formatDateTime(variables('varDateNow'),'MM')

    formatDateTime(variables('varDateNow'),'yyyy')

     

    Then I have a switch case on month value, so in my case I get the month value as "02" then it goes in switch case "02" in which I have mapped the earlier month which is January and then from the year value I substract 1 which gives me earlier year value.

    Switch case based on month value:

    01 : December

    02:  January

    03:  Februray

    04:  March and so on...

     

    Hope this helps.

     

    --------------------------------------------------------------------------------
    If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 377

#2
11manish Profile Picture

11manish 292 Super User 2026 Season 2

#3
Henil Profile Picture

Henil 128

Last 30 days Overall leaderboard