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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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