cancel
Showing results for
Did you mean:
Resolver I

## In a collection, how to create a column where the values should be: multiply a percentage in this item by a the number in the same column but from the item before.

Hello everyone! I really, really need your help.

I need to calculate the total annual spend and the net present value for different projects. For that I have the following information in a table (sample info):

Annual average volume   4000

Program life time in years    8

Cost reductions    3% in 3 years 2% in 2 years

Piece price 1.50

The Rate% for the Present value calculation will be given in an input field in the app

I attached the table I need to create/simulate to be able to perform these calculations in excel. The explanation is as follows:

1. First I need to create a table with number of items from 0 to program life time in years . I store an index in the first column.

2. For column 2 I need to transform the text in the column "Cost reductions" to a column stating the year 0 no cost  reductions, the next three years a reduction of 3% and the next 2 years a reduction of 2%

3. For column 3 I need to calculate the piece price for each year =Piece price of the previous year * (1-cost reduction of this year) (for the year 0 the piece price will be the one given in the item)

4. For the Total Spend column I need to multiply the calculated piece price of this year * annual average volume. The sum of this column will give me the Total Annual spend that I am looking for.

5. For the Present Value column I need to divide the total spend / (1-rate%)^ThisItem.year (the first column). The sum of this column will give me the Present Value

Until now I have created a collection as follows:

ForAll(Sequence(Value(Last(FirstN(Split(ThisItem.CostReduction, " "),3)).Result),1),Collect(Reduction1,{ReducPercentage:Last(FirstN(Split(ThisItem.CostReduction, " "),1)).Result,AnnualVol:LookUp(QBOM,QBOMIDinQBOM=ThisItem.QBOMIDinCBD1).TotalAnnualAvgCmpVolume,Index:CountRows(Reduction1)+1,PiecePrice:Left(Label64_1.Text,Find(" ",Label64_1.Text)),Spend:0}));
ForAll(Sequence(Value(Last(FirstN(Split(ThisItem.CostReduction, " "),7)).Result),1),Collect(Reduction2,{ReducPercentage:Last(FirstN(Split(ThisItem.CostReduction, " "),5)).Result,AnnualVol:LookUp(QBOM,QBOMIDinQBOM=ThisItem.QBOMIDinCBD1).TotalAnnualAvgCmpVolume,Index:CountRows(Reduction2)+CountRows(Reduction1)+1,PiecePrice:Left(Label64_1.Text,Find(" ",Label64_1.Text)),Spend:0}));
ForAll(Sequence(Value(Last(FirstN(Split(ThisItem.CostReduction, " "),11)).Result),1),Collect(Reduction3,{ReducPercentage:Last(FirstN(Split(ThisItem.CostReduction, " "),9)).Result,AnnualVol:LookUp(QBOM,QBOMIDinQBOM=ThisItem.QBOMIDinCBD1).TotalAnnualAvgCmpVolume,Index:CountRows(Reduction3)+CountRows(Reduction2)+CountRows(Reduction1)+1,PiecePrice:Left(Label64_1.Text,Find(" ",Label64_1.Text)),Spend:0}));
ForAll(Sequence(Value(Last(FirstN(Split(ThisItem.CostReduction, " "),15)).Result),1),Collect(Reduction4,{ReducPercentage:Last(FirstN(Split(ThisItem.CostReduction, " "),13)).Result,AnnualVol:LookUp(QBOM,QBOMIDinQBOM=ThisItem.QBOMIDinCBD1).TotalAnnualAvgCmpVolume,Index:CountRows(Reduction4)+CountRows(Reduction3)+CountRows(Reduction2)+CountRows(Reduction1)+1,PiecePrice:Left(Label64_1.Text,Find(" ",Label64_1.Text)),Spend:0}));
ClearCollect(Reduction,Reduction1,Reduction2,Reduction3,Reduction4); Clear(Reduction1);Clear(Reduction2);Clear(Reduction3);Clear(Reduction4);

as you can see the Piece Price the annual spend are not yet calculated.

My questions:

Is there a better way to get the cost reductions into the collection (maybe dynamically)?

How can I create the column piece price? (I have tried with For All, Sequence, Patch, ThisRecord.Index-1 but I can not find the right combination and I can not patch in the same source as the for all)

Is there a way to make a For All inside of a For All to make the calculation of the Total Annual Spend and the Present Value without creating a collection or how would you recommend me to do these calculations?

Every help is welcome!

25 REPLIES 25
Resolver I

I just saw that the piece price is 17.158 and is shown rounded up to 17.16, but the calculation is still done with the 17.158, for this reason there is a difference. If I use the 17.16 as piece price, the values I get are still different (see attachment).

Super User

Thanks for the clarification on the rounding.  That made the difference.

So I am not seeing what you are seeing.  If I plug 17.16 in for the piece price I get exactly what you have when you used 17.16 on the Spreadsheet.

Now, if I used the unrounded number 17.158 I get the exact same numbers you had in the prior spreadsheet:

Everything appears to be exactly what you are getting in the spreadsheet.

What am I missing?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Resolver I

So I see the difference. You are using a CR of     0% in 3 years 3% in 3 years

I am using a CR of    0% in 3 years 3% in 3 years 0% in 2 years

If I remove that last part, I get the numbers you are showing me. The curious thing is that even though in the example 4 we also have a 0% in 4 years at the end, it is not being affected. How is the 0% reduction in the 3 first years considered? Would this affect the number of loops it does at the end? Is it doing 2 additional loops or something? If you add the total number of years mentioned in the CR it results in 8 years, and the project only runs for 6 years. Could this somehow be used to stop the loop at the 6th year? I know that the 0% in 2 years at the end sounds crazy to have, but it is a macro that is getting these numbers into a table format to be able to use it in power apps.

Also, are you getting the error in the button saying that the first argument to Sequence must be between 0 and 50000?

Super User

Yes, I see the issue now if I add the 0% in 2 years.  Which, by itself doesn't really make sense...if the term in years is 6, then 0% in 3 years and 3% in 3 years and 0% in 2 years is 8 years!!

Anyway, I will take a closer look at the formula and see where that becomes a problem.

As for the Sequence error...No, I do not see anything like that.  What are you seeing??

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Resolver I

You know what, you are right. I will find a way to improve my data before using the formula (now that I know where the problem is).

The sequence error is not there every time, so maybe it has to do also with the data I am using. I will have a deeper look into it.

Thank you very much for your help and your solution!

Super User

Very good!  Yes, the formula will be sensitive to the CR format.  It was built around the concept of how you originally had the string.  So, changes to that will potentially result in problems.  If you need to change the format, then the regular expression in that formula would need to be done differently.

Glad you have something working now!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Announcements

#### Take a short Community User Survey | Help us make your experience better!

To ensure that we are providing the best possible experience for Community members, we want to hear from you!    We value your feedback! As part of our commitment to enhancing your experience, we invite you to participate in a brief 15-question survey. Your insights will help us improve our services and better serve the community.   👉 Community User Survey    Thank you for being an essential part of our community!    Power Platform Engagement Team

#### Tuesday Tip | How to Get Community Support

It's time for another Tuesday Tip, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.       This Week: All About Community Support Whether you're a seasoned community veteran or just getting started, you may need a bit of help from time to time! If you need to share feedback with the Community Engagement team about the community or are looking for ways we can assist you with user groups, events, or something else, Community Support is the place to start.   Community Support is part of every one of our communities, accessible to all our community members.   Within each community's Community Support page, you'll find three distinct areas, each with a different focus to help you when you need support from us most. Power Apps: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pa_community_support Power Automate: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpa_community_support Power Pages: https://powerusers.microsoft.com/t5/Community-Support/ct-p/mpp_community_support Copilot Studio: https://powerusers.microsoft.com/t5/Community-Support/ct-p/pva_community-support   Community Support Form If you need more assistance, you can reach out to the Community Team via the Community support form. Choose the type of support you require and fill in the form accordingly. We will respond to you promptly.    Thank you for being an active part of our community. Your contributions make a difference!   Best Regards, The Community Management Team

#### Calling all User Group Leaders and Super Users! Mark Your Calendars for the next Community Ambassador Call on May 9th!

This month's Community Ambassador call is on May 9th at 9a & 3p PDT. Please keep an eye out in your private messages and Teams channels for your invitation. There are lots of exciting updates coming to the Community, and we have some exclusive opportunities to share with you! As always, we'll also review regular updates for User Groups, Super Users, and share general information about what's going on in the Community.     Be sure to register & we hope to see all of you there!