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
k_r
Frequent Visitor

How to show the Opening Stock for a week as the Closing Stock for the previous week?

Hi there, 

I currently have this table that I've created using Original Opening Stock and Closing Stock measures.

k_r_0-1733225321281.png

 

 

Besides Week Index 0, going forward from Week Index 1, I would like to have the Opening Stock for a week as the Closing Stock for the previous week. So for example, Week Index 2's Original Opening Stock should be equal to Week Index 1's Closing Stock.

Is there a way to acheive this without circular dependency errors?

The current DAX formula I have for the two measures are as follows:

Original Opening Stock:
CALCULATE(
SUM(Stock_CLEAN[Unrestricted PAC]),
Stock_CLEAN[Material] = SELECTEDVALUE(Stock_CLEAN[Material]),
Stock_CLEAN[Plnt] IN {"1100", "1500"}
)

Closing Stock:
[Opening Stock] - [Total Demand] + [Total Supply]



1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@k_r , Try using 

 

Opening Stock =
VAR CurrentWeek = SELECTEDVALUE(Stock_CLEAN[Week Index])
VAR PreviousWeek = CurrentWeek - 1
VAR PreviousWeekClosingStock =
CALCULATE(
[Closing Stock],
Stock_CLEAN[Week Index] = PreviousWeek
)
RETURN
IF(
CurrentWeek = 0,
[Original Opening Stock],
PreviousWeekClosingStock
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

1 REPLY 1
bhanu_gautam
Super User
Super User

@k_r , Try using 

 

Opening Stock =
VAR CurrentWeek = SELECTEDVALUE(Stock_CLEAN[Week Index])
VAR PreviousWeek = CurrentWeek - 1
VAR PreviousWeekClosingStock =
CALCULATE(
[Closing Stock],
Stock_CLEAN[Week Index] = PreviousWeek
)
RETURN
IF(
CurrentWeek = 0,
[Original Opening Stock],
PreviousWeekClosingStock
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






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.