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
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors