cancel
Showing results for
Did you mean:
Helper II

## Loop to Create DATES based on range when creating new rows

Hello,

I have a flow where one trigger gets the amount based on the number of years and auto-creates the days sequentially.

The steps,
Once an amount is created, and a number of years are put, a flow triggers, I then proceed to list items to be able to get other metadata which I will use to autogenerate the rows.

The issue I am having is, let's say I have an amount calculated by the number of years: 2,000,000/5 = 400,000
Ideally, it should auto-create 5 rows, a year apart.
so
Amount     Due date
400,000     3-8-2023
400,000     3-8-2024
400,000     3-8-2025
400,000     3-8-2026
400,000     3-8-2027

Instead from my formula the year is repeated only once for all five rows, Could it be because I have a do until, where I'm asking the rows to be auto-created until the rows are 0, since after the loop I ave a decrement variable by 1?

My date is coming from the trigger, SigningDate, this is the date I will be using to generate the DueDates based on a number of years.

Really need help on this.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

If I understand it correct I would do it this way:

From: range(0, YOURNUMBEROFYEARS)

Map - Amount: div(YOURAMOUNT, YOURNUMBEROFYEARS)

Map - Due date: addToTime(YOURDATE, item(), 'Year''yyyy-MM-dd')

After that you can iterate the array and do whatever you need to do.

6 REPLIES 6
Super User

Can you show a screenshot of the formula you are using and the outputs?

You will probably need to incorporate the addToTime() expression to adjust the years of your Signing Date. But I don't know what you are using as a formula, so it depends.

Helper II

Hi @wskinnermctc  thanks, though I think the issue might be with how I am looping Maybe since my formula is adding a year but only one for all rows, instead of the subsequent ones it's only adding one

I have initialized a variable called no of years it's a float type from trigger, "No of Years", another variable where am dividing the amount, and another variable where am storing the date,

I then have a do until where I've stated  no of years is equal to 0
I then have an apply to each for creating the rows based on the filtered items on get items, for my due date I've used the variable for my date with the formula.

I then have a Decrement variable where I am decrementing the Noofyears

Super User

If I understand it correct I would do it this way:

From: range(0, YOURNUMBEROFYEARS)

Map - Amount: div(YOURAMOUNT, YOURNUMBEROFYEARS)

Map - Due date: addToTime(YOURDATE, item(), 'Year''yyyy-MM-dd')

After that you can iterate the array and do whatever you need to do.

Helper II

Thanks, but where does that sit in the flow, because I have other columns to populate from a table in Dataverse. only those two columns are dynamic from a formula.

Super User

Instead of your current loop you do an apply to each of the created array.

I don’t know where you get your other data. If you have problems implementing the solution you will have to provide mor input about the current problem.

Helper II

Thanks, this worked.

Announcements

#### Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Our team will be reviewing posts using the new "Copilot" label to ensure we highlight and amplify the most relevant and recent content, so you're assured of high-quality content every time you visit. If you share a post that gets featured in the curated gallery, you'll get a PM in the Community to let you know!The curated gallery is ready for you to experience now, so visit the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community. We can't wait to see what you "cook" up!