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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
daowei
Regular Visitor

inventory aging buckets with FIFO

Dear all,

 

I have been struggling with a caculation for a few days, but cannot find a way to get around the circular dependency error.  

PurchaseSaleAge Corrected Stock at the begining of each week  (Inc. Discard)
  1w2w3w4w5w6w (Discard)
20002502000000002000
 5500175000001750
 5000012000001200
1750250175000700002450
 250017500045002200
 775001750002001950
1750350175000975002725
350075350017500062505875
 900035001750005505800
1500450150003500850005850
 1325015000350040005400
30001503000015000257507075
27506252750300001500024259675
500011755000275030000875011625
3500282535005000275027000013950

Here is a example of aging buckets I created in Excel, based on four assumptions

1. Before simulation we have the values in first row, start with 2000 in 1 week aging bucket.

2. The aging bucket display number of stock at the begining of each week. 

3. First in first out

4. Any item older than 6 weeks will be discarded, therefore in the next week unused item in week 6 will be zero. 

 

In Excel it's easy to caculate remaining units from last week for deduction, but in PowerBI caculated column I keep getting circular dependency error, as I try to sumx previous values. Any suggestions on how to solve this problem?

4 REPLIES 4
bhanu_gautam
Super User
Super User

@daowei To avoid circular dependency errors in Power BI when calculating inventory aging buckets with FIFO, you can use measures instead of calculated columns.

 

Ensure you have a table with your purchase and sale data, including the week number.

 

Calculate the total purchases for each week.

     Total Purchases = SUM('Inventory'[Purchase])
 
Calculate the total sales for each week.
Total Sales = SUM('Inventory'[Sale])
 
DAX
Stock at Beginning of Week =
VAR CurrentWeek = MAX('Inventory'[Week])
VAR PreviousWeekStock =
CALCULATE(
[Stock at End of Week],
FILTER(
'Inventory',
'Inventory'[Week] = CurrentWeek - 1
)
)
RETURN
IF(
ISBLANK(PreviousWeekStock),
[Total Purchases],
PreviousWeekStock
)
 
Stock at End of Week =
[Stock at Beginning of Week] + [Total Purchases] - [Total Sales]
 
Stock 1 Week =
CALCULATE(
[Stock at End of Week],
FILTER(
'Inventory',
'Inventory'[Week] = MAX('Inventory'[Week]) - 1
)
)
 
Discarded Stock =
CALCULATE(
[Stock at End of Week],
FILTER(
'Inventory',
'Inventory'[Week] <= MAX('Inventory'[Week]) - 6
)
)

 




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

Proud to be a Super User!




LinkedIn






Hello bhanu_gautam,

 

I've tried to create measures with your methods, but Powerbi report a circular dependency between [stock at end of week] and [stock at beginning of week] again... 

@daowei , 

 

Stock at Beginning of Week =
VAR CurrentWeek = MAX('Inventory'[Week])
VAR PreviousWeekStock =
CALCULATE(
SUMX(
FILTER(
'Inventory',
'Inventory'[Week] = CurrentWeek - 1
),
[Total Purchases] - [Total Sales]
)
)
RETURN
IF(
ISBLANK(PreviousWeekStock),
[Total Purchases],
PreviousWeekStock
)

 

and DAX
Stock at End of Week =
VAR CurrentWeek = MAX('Inventory'[Week])
RETURN
CALCULATE(
[Stock at Beginning of Week] + [Total Purchases] - [Total Sales],
FILTER(
'Inventory',
'Inventory'[Week] = CurrentWeek
)
)




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

Proud to be a Super User!




LinkedIn






Hello bhanu_gautam, thank you for your reply, but the result is still a bit far from my expectation.

daowei_0-1726228050405.png

 

Maybe my previous description was not so clear. Here is the final table I'd like to get Picture1.pngThe remaining Purchase amount from current week goes to AGE WEEK1 bucket, that's easy. Then in next week, all remaining amount from AGE Week 1 goes to AGE WEEK 2 bucket etc.

 

If a bucket has less than the remaining amount for sale for that week, then 0.

The consumption starts from the oldest AGE bucket (week 6), if amount insufficent, then move to age bucket week 5 etc. 

 

So how do I offset previous remaining amount into next age bucket and 'loop' this for six times. 

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.