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
William_Moreno
Helper II
Helper II

Circular dependency in invetory calculate

Hello everyone,
I need to build a formula in the powerbi to calculate the openning inventory, but if the date is not the same as today, this should consider t of closing inventory of the previous day.
When I try to do this the powerbi mesage is circular dependecy,
Below follow a example:

UnitProductDateOpenning InventoryManufacturing productSalesClosing Inventory
DallasXFG04421/12/202079218010962
DallasXFG04422/12/2020962   
DallasXFG04423/12/2020    
DallasXFG04424/12/2020    
DallasXFG04425/12/2020    

 

Can someone help me?
Thanks in advanced.

 

3 REPLIES 3
Anonymous
Not applicable

Hi  @William_Moreno ,

I customize the data of manufacturing products and sales:

v-yangliu-msft_0-1608686741366.jpeg

Here are the steps you can follow:

1. Enter power query through transform data and select add column --- index column --- from 1 to generate the index

v-yangliu-msft_1-1608686741369.jpeg

2. Create Measure.

Closing Inventory_measure =
var _index=MAX('Table'[Index])
var _1=CALCULATE(SUM('Table'[Openning Inventory]),FILTER(ALL('Table'),[Index]<=_index))
var _2=CALCULATE(SUM('Table'[Manufacturing product]),FILTER(ALL('Table'),[Index]<=_index))
var _3=CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),[Index]<=_index))
var _result=_1+_2-_3
return
IF(MAX('Table'[Index])=1,962,_result)
Openning Inventory_measure =
var _1=
CALCULATE([Closing Inventory_measure],FILTER(ALL('Table'),[Index]=MAX([Index])-1))
return
IF(MAX('Table'[Index])=1,792,_1)

3. Result:

2020.12.23.111.jpg

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This is what I am looking for.  Thank you very much Liu Lang

amitchandak
Super User
Super User

@William_Moreno , Try meausre like

 

Openning Inventory =
var _min = minx(all(Table), Table[Month]) //or use date
return
calculate(sum(Table[Openning Inventory]), filter(Table, Table[date] =_min)) - calculate(sum(Table[ Manufacturing])-sum(Table[product Sales]), filter(Table, Table[date] <max(Table[date)))


Openning Inventory =
calculate(sum(Table[Openning Inventory]), filter(Table, Table[date] =calculate(min(Table[date]), allexpcept(Table,table[Product]))) - calculate(sum(Table[ Manufacturing])-sum(Table[product Sales]), filter(Table, Table[date] <max(Table[date)))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.