Forum Discussion
Recursive Measure PowerBI
DAX does not generally like recursion. See the article:
https://community.powerbi.com/t5/Community-Blog/Runge-Kutta-and-the-Limits-of-DAX/ba-p/357501
However, I wrote a blog article recently that might help with your situation:
https://community.powerbi.com/t5/Community-Blog/For-and-While-Loops-in-DAX/ba-p/636314
Could you post sample data as text and expected output? Would help tremendously.
- Pdecis7 years agoFrequent Visitor
I would like this :
Stock = 7316 (january)
Stock for February = Stock January (7316)+Entrées-Sorties
Stock for March = Stock February + Entrées + SortiesIn Power BI, Sorties ia a measure link with few measures.
....
Thanks- Greg_Deckler7 years agoCommunity Champion
Hmm, well I gave this a lot of thought. Not sure I have what I need from a sample data perspective to give you a detailed solution, but I did come up with a way to emulate recursion in DAX that might work for your purposes. See here:
- d_gosbell7 years agoSuper User
While recursion is elegant from a coding point of view there are usually also non-recursive solutions for most problems.
I'm not sure if I understand your issue correctly, but it looks to me like you are trying to calculate stock on hand based on looking at the Incoming (Entrées) and Outgoing (Sortes) stock. If this is the case and your period is based off a Date column in your model you could do this by calculating a lifetime to date for Incoming and Outgoing and subtract one from the other.
eg
Stock =
VAR _prevEntrées = SUMX( Filter('table1'[DateColumn], 'table1'[DateColumn] <= MAX('table1'[DateColumn]), [Entrées] )
VAR _prevSorties = SUMX( Filter('table1'[DateColumn], 'table1'[DateColumn] <= MAX('table1'[DateColumn]), [Sorties] )
RETURN _prevEntrées - _prevSorties