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 / Using Compose in a swi...
Power Automate
Answered

Using Compose in a switch statement?

(0) ShareShare
ReportReport
Posted on by 149

Greetings: 

 

I'm an experienced programmer but brand new to Power Automate so I'm experiencing the usual frustrations with something that is very easy on one platform/language taking hours and and hours of frustration to accomplish on another.  

 

I have a very simple objective: left padding a number (x) with '0' based on it's value so that:

   * if x <10 then the string value of x should be '00X', e.g., '009

   * if x <100 then the string value of x should be '0X', e.g., '046'

   * otherwise the string value of x should be 'X', e.g., '238', '1479', etc.

where X is the string value of the integer x.

 

To me this is a classic case where a switch statement would be used to reset the value of the variable X.  For example, in the case where x <10 I would write X= concat('00',X) and etc. with the other cases. This doesn't work because, apparently in Power Automate, you can't assign a value to a variable that refers to the existing value of that variable (a simple assignment statement in other languages). Even if I use a different variable name I'm still running into issues with using the concat function when setting a variable.

 

I've had better luck with concat when using Compose instead of Set Variable.  However, the problem there is that you can only assign a 'compose' output name in one action. This doesn't work in the Case branches of a Switch statement. Compose actions, and the outputs that bear their name, appear to be unique. So how do you come out of a switch statement like this with a single variable that is padded with '00' or '0' or '' based on the input value if each Compose action has to have a unique name?

 

Again, I'm brand new at this, but what would take me, say, 5 seconds to solve in Python has taken me 5 hours in Power Automate and I still haven't solved it!  Any help would be appreciated!

 

Thanks, in advance.

 

 

   

Categories:
I have the same question (0)
  • Verified answer
    Rhiassuring Profile Picture
    8,690 Moderator on at

    Hi there, 

     

    I think it's just a matter of if it's 100 or more, keep as is. If it's not, use 

    formatNumber(variables('intNumber'),'000''en-us')
     
    FormatNumber() is definitely what you're looking for.
  • Baltner Profile Picture
    149 on at

    Yes, this works,. Also, it turns out that concat also works.  It didn't for me because I was typing the expression in directly rather than going through the dynamic variables expression builder.  Therefore the JSON code was wrong. 

     

    Thanks for the help.

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…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
trice602 Profile Picture

trice602 398 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 323 Super User 2025 Season 2

#3
Expiscornovus Profile Picture

Expiscornovus 183 Most Valuable Professional

Last 30 days Overall leaderboard