Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
ChouaibBenali
New Member

Math Wizadery Recursion

Hi everyone, i looked arround and since i'm no math guru i really need help coming up with a solution for this problem, i need to replicate this logic: 

 JanuaryFebruary  MarchApril
Sell Out    17 014 679,20    16 188 004,97    22 978 536,89    20 032 740,21
Sell In    19 980 043,44    20 248 217,04    24 824 416,44    21 868 254,12
Estimation Stock       2 965 364,24       7 025 576,31       8 871 455,86    10 706 969,77

 
So Estimation Stock for January is just Sell In - Sell Out but for Feburay it's (Sell In - Sell Out) + Estimation Stock of January

I tried to come up with 3 measures to do that but no luck so far, kinda stuck actually, i dunno if the problem is algorithmic as it seems that it needs Recursion or there's a simple workarround that i'm not able to see, here's the 2 Dax Measures that i wrote for it:

This measure calculates the differance 

A =
VAR CurrentMonthSellOut = [Total des ventes secondaire en litre OUTSB] -
VAR CurrentMonthSellIn = [Sell IIn Reel 1]
RETURN
    CurrentMonthSellIn  - CurrentMonthSellOut


Estimation Stock =
VAR CurrentMois= SELECTEDVALUE('Période'[TheDate].[NoMois])
VAR PreviousMonthEstimationStock= CALCULATE([Estimation Stock],PREVIOUSMONTH('Période'[TheDate]))
RETURN
       IF( CurrentMois = 1,  [A], 
PreviousMonthEstimationStock + [A] 
          )

Obviously this will not run as it is self referencing itself,it's just to help you understand the logic.


Can anyone help me about it ?

1 ACCEPTED SOLUTION
xifeng_L
Super User
Super User

Hi @ChouaibBenali ,

 

We can calculate the cumulative Sell-In minus the cumulative Sell-Out, and hopefully the following expression will inspire you.

 

xifeng_L_0-1715701128938.png

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

View solution in original post

2 REPLIES 2
xifeng_L
Super User
Super User

Hi @ChouaibBenali ,

 

We can calculate the cumulative Sell-In minus the cumulative Sell-Out, and hopefully the following expression will inspire you.

 

xifeng_L_0-1715701128938.png

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

Greg_Deckler
Super User
Super User

@ChouaibBenali Generally recursion is not possible. However, in your case you may be able to get around that limitation by creating a measure for Previous Month Estimation Stock, Current Month Estimation Stock and your A measure.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.