Forum Discussion
Anonymous
5 years agoNot applicable
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...
Anonymous
5 years agoNot applicable
Exactly ERD ! 🙂
ERD
Community Champion
5 years agoIf 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!