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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Manjarigoyal1
Frequent Visitor

How to substract current row with next row and then substract the result to next row?

I am trying to substarct the row1 to row2 and then the result will be substracted from row 3 and so on. I am looking for M Query NOT in DAX. Below is the sample data with expected result. Thanks for the help.

Delivery WeekTotal DeliveryExpected Result
31-Dec-232542525425
6-Jan9225333
13-Jan17225161
20-Jan12225039
27-Jan11224927
3-Feb21824709
10-Feb16024549
17-Feb15424395
24-Feb13524260
2-Mar18024080
9-Mar18423896
16-Mar15123745
23-Mar18323562
30-Mar18223380
6-Apr17123209
13-Apr18023029
20-Apr14022889
27-Apr2122868
1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

there are so many running total solutions out there... 

let
    lst = List.Buffer(Table.ToRows(your_table)),
    res = Table.FromList(
        List.Generate(
            () => [i = 0, c = lst{0},  s = c{1}],
            (x) => x[i] < List.Count(lst),
            (x) => [i = x[i] + 1, c = lst{i}, s = x[s] - c{1}],
            (x) => x[c] & {x[s]}
        ),
        (x) => x, 
        {"week", "delivery", "expected"}
    )
in
    res

View solution in original post

1 REPLY 1
AlienSx
Super User
Super User

there are so many running total solutions out there... 

let
    lst = List.Buffer(Table.ToRows(your_table)),
    res = Table.FromList(
        List.Generate(
            () => [i = 0, c = lst{0},  s = c{1}],
            (x) => x[i] < List.Count(lst),
            (x) => [i = x[i] + 1, c = lst{i}, s = x[s] - c{1}],
            (x) => x[c] & {x[s]}
        ),
        (x) => x, 
        {"week", "delivery", "expected"}
    )
in
    res

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.