Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Fram
New Member

Calculation based on previous row with dependency between columns

I have some simple excel formulas that I would like to calculate in power query M. The issue I see is that each row is dependent on the outcome of the previous row but that there is also a column dependency as well

  • total = previous row total + fixed value + loss
  • loss = previous row total * multiplier

Fram_2-1666173983935.png

 

Fram_3-1666174045912.png

Sample file: https://easyupload.io/lf4337

 

I have already looked at index columns, List.Sum function, etc but I don't get what I'm looking for because of the column dependency.
How can I make this work in power query?

 

1 ACCEPTED SOLUTION

Hi @Fram ,

 

Sorry for my wrong understanding.

If your Loss is calculated in terms of Total, but your Total is also calculated in terms of Loss, it seems impossible to implement in Power Query.

This is because in Excel, each cell of yours can be treated as an independent operation, not in Power Query.

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @Fram ,

 

Here's my solution.

1.Add an index column.

vstephenmsft_0-1666245068511.png

 

2.Add a custom column as Total.

vstephenmsft_1-1666245108181.png

vstephenmsft_2-1666245119552.png

3.Get the previous row based on Total column. Reference: Value from previous row – Power Query, M language – Trainings, consultancy, tutorials (exceltown.com...

vstephenmsft_3-1666245180979.png

vstephenmsft_4-1666245199115.pngvstephenmsft_5-1666245207208.pngvstephenmsft_6-1666245213454.png

Replace error with blank.

vstephenmsft_7-1666245268959.png

vstephenmsft_8-1666245285459.png

vstephenmsft_10-1666245357103.png

 

4.After change the type Previous Total to Decimal Number. We can add a custom column to get Loss.

vstephenmsft_9-1666245322838.png

vstephenmsft_11-1666245429583.png

vstephenmsft_12-1666245437340.png

Remove the unneeded columns.

vstephenmsft_13-1666245497511.png

 

You could download my attachment for details.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Hi,

 

Thanks for your contribution. If you compare the values you will see that the result is different, so no solution for me so far.
The issue I see is in step 2: you calculate a custom total, but this one does not include the loss column and it should (for some reason you add the multiplier to the fixed value, while in fact the multiplier in the excel formulae applies to the previous total, with the issue that the previous total again is dependend on the loss of the previous total and the previous previous total).

 

 

Hi @Fram ,

 

Sorry for my wrong understanding.

If your Loss is calculated in terms of Total, but your Total is also calculated in terms of Loss, it seems impossible to implement in Power Query.

This is because in Excel, each cell of yours can be treated as an independent operation, not in Power Query.

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors