Forum Discussion

Hart1969's avatar
Hart1969
Regular Visitor
3 years ago
Solved

Power Query compute a value based on previous row value

Hello,

I want to have a solution for the following problem:

Ich have several releases (e.g. 22.1, 22.2, 22.3, 22.4, 23.1, 23.2,23.3).

In each release i have a "needed capacity" and a "available capicity".

Now i want to compute the columns surplus and backlog from these values:

Example:

Releaseneeded capacityavailable capicitysurplusbacklogdescription
22.13530555 days remaining in backlog
22.2453015205 day from last release plus 15 days from current release remaining in backlog
22.32030-101010 days are free in current release reducing the backlog by 10
22.41030-20020 days are free in current release reducing the backlog to 0 (because backlog cannot be negative)
23.14530151515 days remaining in backlog
23.21030-20020 days are free in current release reducing the backlog to 0 (because backlog cannot be negative)
23.34030101010 days remaining in backlog
23.42530555 days are free in current release reducing the backlog by 5

  

The surplus column ist just "needed capacity - available capacity"

The problem is calculating the backlog. It must compute the backlog from the previous step: if ([backlog previous step] + [surplus] > 0 then [backlog previous step] + [surplus] else 0)

so it must compute how much effort of the backlog will be processed with this release. but the backlog can not be lower than 0.

 

How do i solve this problem with power query?

2 Replies

  • Mikelytics's avatar
    Mikelytics
    Resident Rockstar

    HI Hart1969 

     

    Is each release one row or can be one release in multiple rows?

    Have you thought about the following (should work if one release is one row)? 

    1) Make sure that your list sorted ascending by release ID

    2) create an index column (standard Power QUery function) -> now each row should have a unique numeric index

    3) now create a custom column like previousIndex = [Index] -1 

    4) now create a self join based on [previous index] and [index]

    5) now you should have the previous list row in each row and you can expand the information you need for further transformation.

    Best regards

    Michael

    -----------------------------------------------------

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your thumbs up!

    @ me in replies or I'll lose your thread.

    -----------------------------------------------------

    LinkedIn