Forum Discussion
Adding conditional column with either value from other column OR the value from the row above
Hi All,
I'm still trying to find my way in PowerBi and to solve some interesting questions, which I have.
I have this query that generates the upper table: it put some expected mutations for a specific item no. in a time line and checks whether theoretticaly the stock is not sufficient. So this is nice, but now I want to see what my options are if the stock is not sufficient for the expected mutation:
- If there is an expected Purchase Order due to arrive just before the mutation, I would like to know when and what amount: if I know which Purchase Order I can call the supplier to try to increase the ordered amount
- If there is an expected Purchase Order due to arrive just after the mutation, I would like to know when and what amount: if I know which Purchase Order I can call the supplier to try to get the items easlier.
Can someone tell me how to add such a conditional column? So for 'Previous_purchase' I would like to check if the column 'type' has the value 'Purchase' on the previous row and if so, I woulde like to get the Reference and put it in the column 'Previous_purchase'. If the column 'type' has not the value 'Purchase' on the previous row, then I would like in 'Previous_purchase' to repeat the value of the previous row.
If I'm able to make such an overview, I only have to look at the row with the negative stock after mutation, and I can see directly which Purchase Order(s) are involved.
I hope you can help me out, thanks in advance!
11 Replies
- lbendlinSuper User
There are a couple of tools at your disposal. Read about nested IFs, SWITCH, and COALESCE. Pick whatever you like best.
- DanielB_NLHelper I
I'm working with swicht and nesteds IF's, but I guess I have to start with getting the value of 'reference' for the row direct after a Purchase row: I've tried and googled a while, and came up with the code below, but it's not working.
previous_purchase = VAR CurrentRowType = Todays_future[type] VAR PreviousRowType = CALCULATE(MAX(Todays_future[type]), FILTER(ALL(Todays_future), Todays_future[index] = EARLIER(Todays_future[index]) - 1)) RETURN IF(CurrentRowType = "Purchase (PO)", Todays_future[reference], BLANK())
- lbendlinSuper User
Try not to use EARLIER. Use variables instead.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information or anything not related to the issue or question.
If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523- DanielB_NLHelper I
Hi, thank you for the swift reaction. Variables is competely new to me, so I really hope you can help me a little further. I've created a small dataset in an CSV-file and made it available from my Dropbox account:
I've created an Excelsheet with the desired results:
If I have the extra columns, in my Dashboard I can filter on rows that have in the column 'Stock_after_booking' a value < 0. By doing this I isolate all my project which have a potential problem and I also see which Purchase Orders I can try to influence in order to solve the problem.
I really hope you can help me with this, thanks in advance for your reply!
Kind regards, Daniel