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 / How to append a random...
Power Automate
Answered

How to append a random numerical value to an image file through Compose

(0) ShareShare
ReportReport
Posted on by 299

Within my flow, I'm processing an "Apply to each" loop to get image names collected from my Microsoft Form.

Below is an example of my Compose step, which is retrieving the name of my image and replacing blank spaces with underscores....

 

kensley_0-1627569391219.png

 

That will help my image name go from the image file.jpg to the_image_file.jpg

But what can I do to append a random value from 1 - 100 to the end of the name, but before the extension, so it looks like the_image_file_10.jpg, or the_image_file_57.png, or the_image_file_98.gif. It all depends on the file format the end-user submits, but the random value should be there regardless.

 

Many thanks on any tips

 

Categories:
  • Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @kensley,

     

    I would use the split and concat functions to achieve this. 

     

    Below is an example expression of that approach.

    Replace the hardcoded value 'The image file.jpg' by your dynamic content. In this example I am adding the _01 just before the dot.

     

    concat(split(replace('The image file.jpg', ' ', '_'), '.')[0], '_01.', split('The image file.jpg', '.')[1])

      

  • CU09091757-0 Profile Picture
    299 on at

    Thank you so much for the learning on this. How would you replace your static '_01.' with rand(1,100) in that equation? I tried doing it on my end but Power Automate is telling me invalid expression... 

  • Verified answer
    Expiscornovus Profile Picture
    34,005 Most Valuable Professional on at

    Hi @kensley,

     

    That would be something like this:

     

    concat(split(replace('The image file.jpg', ' ', '_'), '.')[0], '_', rand(1,1000), '.', split('The image file.jpg', '.')[1])

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 299

#2
11manish Profile Picture

11manish 274 Super User 2026 Season 2

#3
Henil Profile Picture

Henil 119

Last 30 days Overall leaderboard