- Power Apps Community
- Welcome to the Community!
- News & Announcements
- Get Help with Power Apps
- Building Power Apps
- Microsoft Dataverse
- AI Builder
- Power Apps Governance and Administering
- Power Apps Pro Dev & ISV
- Power Apps Portals
- Connector Development
- Power Query
- GCC, GCCH, DoD - Federal App Makers (FAM)
- Power Platform Integration - Better Together!
- Power Platform Integrations
- Power Platform and Dynamics 365 Integrations
- Community Blog
- Power Apps Community Blog
- Galleries
- Community Connections & How-To Videos
- Community App Samples
- Webinars and Video Gallery
- Canvas Apps Components Samples
- Kid Zone
- Emergency Response Gallery
- Events
- 2021 MSBizAppsSummit Gallery
- 2020 MSBizAppsSummit Gallery
- 2019 MSBizAppsSummit Gallery
- Community Engagement
- Community Calls Conversations
- Experimental
- Error Handling
- Power Apps Experimental Features
- Community Support
- Community Accounts & Registration
- Using the Community
- Community Feedback

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Power Apps Community
- Forums
- Get Help with Power Apps
- Building Power Apps
- Re: In a collection, how to create a column where ...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- « Previous
- Next »

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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.

11-27-2020
07:56 AM

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!

Solved! Go to Solution.

25 REPLIES 25

- « Previous
- Next »

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

12-06-2020
03:50 AM

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).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

12-06-2020
09:44 AM

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!**

NOTE: My

Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

12-07-2020
01:17 AM

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

12-07-2020
05:13 PM

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!**

NOTE: My

Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

12-08-2020
12:53 AM

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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

12-08-2020
06:08 AM

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!**

NOTE: My

Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

- « Previous
- Next »