Guenther from Hamburg
Guenther from Hamburg

Reputation: 11

Power Query, row by row the sum of the next 3 values

I have a power query table, 1 column with integer values. In another column, the sum of the current row and the other 2 rows should be calculated row (cell) by row (cell). - In plain Excel, I calculate it like this:

 B1: = SUM(B1:B3)
 B2: = SUM(B2:B4)
 B3: = SUM(B3:B5)
 ...

How can I solve this with Power Query? If an error occurs in the last 2 lines, this is negligible.

Upvotes: 0

Views: 1764

Answers (1)

Marc Pincince
Marc Pincince

Reputation: 5202

Is this what you're looking for?

If you start with this as your Source table:

enter image description here

Then if you add a custom column set up like this:

enter image description here

You'll get this:

enter image description here

Here's the M code, loading it from a spreadsheet's workbook, where the data is in a table named Table1:

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Custom", each List.Sum(List.Range(Source[Column1],[Column1]-1,3)))
in
#"Added Custom"

Upvotes: 1

Related Questions