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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.