Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Fetch previous and next row based on column value

Hi I have a table where I want to create two new columns with the time stamp of the next and previous status change of fk_order_id. It's easily solvable in DAX, but I would like to do this in M to...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous ,

     

    According to your DAX, I think you want to group by the ID column to get the value of the previous or next row. The following is the method in Power Query.

    1.Refer to this article to get a ranking by category. And copy the original table to get the second table, the first table sorting starts from 2, and the second table sorting starts from 1.

     

     

     

    2.Then merge two tables.

     

     

    3.Expand the table

     

    What the example shows is to get the next row. If you want to get the previous row, just change the rank order.

    You can check more details from the attachment.

     

     

    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.