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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

PowerPivot Circular Reference Help

Can someone please help with the attached. I am trying to calculate the Production and Closing inventry based on demand, safety stock and opening stock. The production & opening calculation is dependent on the closing inventory of the previous period.  I get into a circular reference issue in power pivot. 

 

Production = Demand + Safety Stock - Opening Inventory

Closing = opening + Production - Demand

Opening = closing of previous period except for 1st period.

 

OscarD_0-1657876063826.png

Output expected:

OscarD_1-1657876303688.png

Example File 

 

Appreciate if anyone can help.

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

To the best of my knowledge, this is circular logic even to a layperson (not an MS Excel user).  Production depends up on the closing stock of the previuos month and closing stock of the previous month depends up on the production in that month.  Even if you try to create formulas for this in an MS Excel file, how you will solve this.  What will those formuals be?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hello,

 

Implementing in excel is straightforward. The production and closing calculations for the first period is different from the remaining periods.

 

First Period Production Calculations

OscarD_1-1658032717148.png

 

Second Period and onwards calculation

OscarD_2-1658032762700.png

 

First period closing calculation

OscarD_3-1658032791345.png

Second Period and onward closing calculations

OscarD_4-1658032831624.png

 

Final overall desired output (production and closing and calculated data, rest are input data)

OscarD_5-1658032868501.png

implementing this in excel is easy, but i am trying for a PBI solution as there are 100's of SKUs that I need to apply it to.

 

Thanks 

OD

 

 

 

amitchandak
Super User
Super User

@Anonymous , You need to create measure like

 

Inventory / OnHand =
[Intial Inventory] + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date]))) // [Intial Inventory]  is measure

Inventory / OnHand =
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),all('Date')) + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date])))

 

for opening

Inventory / OnHand =
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),all('Date')) + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <Minx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <Minx(date,date[date])))

 

use date from date table in visual and slicer

 


To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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