Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

New column based on fixed amount

Hi

 

I've got two tables named Procurement and Stock.

Procurement contains columns "Confirmed delivery date" and "Procurement Amount".

Stock contains columns "Available stock", which is a current fixed amount. The tables are related based on "SKU" which is a part of both tables.

 

So right now i've got a matrix table looking like this:

 

Product                    Procurement Amount                    Available Stock

SKU1                                   718                                            -377

     16. april 2021                 268                                            -377

     14. may 2021                 151                                            -377

     24. june 2021                 149                                            -377

     4. july 2021                     150                                           -377

 

I want to create a column stating the available stock after the procurement amount and thereby being capable of possibly creating a date table where "New available stock" > 0 in order to show the next date that entails available stock. So essentially something like:

 

Product                    Procurement Amount                    Available Stock                    New Available Stock

SKU1                                   718                                            -377

     16. april 2021                 268                                            -377                                      -109     

     14. may 2021                 151                                            -377                                        42(-109+151)            

     24. june 2021                 149                                            -377                                        191(42+149)     

     4. july 2021                     150                                           -377                                        341(191+150)

 

And afterwards create a table visual stating next available stock date = 14. may 2021.

 

Hope you can help. 

 

 

5 Replies

  • selimovd's avatar
    selimovd
    Icon for Most Valuable Professional rankMost Valuable Professional

    Hey Anonymous ,

     

    when you have a column with the procurement amount and no other column, then it's hard to calculate the new amount. Do you have another column that shows the consumption of the product in the time frame?

     

    I also don't know what I should do with the column "Available Stock". You write -377 every row but I don't see that you really use that column.

     

     Could you explain your columns a little better?

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
     
    Best regards
    Denis
     

     

  • ERD's avatar
    ERD
    Icon for Community Champion rankCommunity Champion

    Hello Anonymous ,

    Well, from the examples you've provided here is what can be concluded:

    • you have a constant here which is called Available Stock and = -377 
    • your new column calculation:
      • first element = constant + current Procurement Amount (-377 + 268)
      • all other elements = current Procurement Amount + previous row calculation result

    Is this what you want to achive?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Exactly ERD ! 🙂

      • ERD's avatar
        ERD
        Icon for Community Champion rankCommunity Champion

         If you want to have a Calculated DAX column that uses the previous row's calculated value as an input, thenDAX won't help you as DAX cannot do recursion. You can read the explanation here: Refer to previous row of same column.

        Power Query instead can be used to achieve the result.

        Here is the code that might help (it might be not the most elegant one, but it works):

         

        #"Added Index" = Table.AddIndexColumn(#"Previous step", "Index", 1, 1, Int64.Type),
        #"Added CalcStep1" = Table.AddColumn(#"Added Index", "CalcStep1", each if [Index] = 1 then -377 + [ProcurementAmount] else [ProcurementAmount]),
        #"Added Column" = Table.AddColumn(#"Added CalcStep1", "Result", each  List.Accumulate(List.Range(#"Added CalcStep1"[CalcStep1],0,[Index]),0,(state,current)=> state+current)),
        #"Removed Columns" = Table.RemoveColumns(#"Added Column",{"Index", "CalcStep1"})

         

        The idea here was to create an Index column, get the list of Procurement Amount values with  the first element changed by constant and then calculate the result. Transitional columns may be deleted afterwards.

        In a table visual any filter can be used further (like Result >0, etc.).

         

         

        Did I answer your question? Mark my post as a solution!