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
IvanS
Helper V
Helper V

Aging of the items on the stock & outside of stock

Hello,

 

I would need your advices and best practices how to calculate aging of the items on Item Ledger table. The task is clear - I need to calculate aging of the items which are

1. Currently on the stock

2. Were on stock in the past but there is no quantity left on stock

 

My table looks like below:

Entry_Ref.Posting dateEntry_TypeItem_NoLocation_CodeQuantity
11.1.2022PurchaseAA-1LONDON5
210.1.2022SaleAA-1LONDON-5
315.1.2022PurchaseBB-2PARIS3
417.1.2022TransferBB-2PARIS-1
517.1.2022TransferBB-2LONDON1
620.3.2022SaleBB-2PARIS2
71.4.2022PurchaseCC-3PARIS10
81.5.2022PurchaseDD-4PARIS7
915.5.2022SaleCC-3PARIS-5
101.6.2022TransferCC-3PARIS-2
111.6.2022TransferCC-3LONDON2
121.6.2022SaleDD-4PARIS-7

 

I would like to calculate:

1. Inventory Flag - which Item_No is still on stock in any warehouse and which is out of stock.

2. If still on stock, then to calculate aging based on Purchase posting date and today's date.

3. If not on stock anymore, then to calculate aging based on Purchase posting date and last Sale posting date.

 

I am more than happy if this will be new calculated table derived from the previous table. Example:

Item_NoInventory FlagQuantityAging in days
AA-1Out of stock09
BB-2On stock1difference between 15.1 and today's date
CC-3On stock5difference between 1.4 and today's date
DD-4Out of stock031

 

Hopefully, my explanation is clear enough.

Thank you for any help. 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can create a table like

Stock summary = GENERATE(
    VALUES( 'Table'[Item_No] ),
    VAR itemNo =
        SELECTEDVALUE( 'Table'[Item_No] )
    VAR currentStock =
        CALCULATE( SUM( 'Table'[Quantity] ) )
    VAR lastPurchaseDate =
        CALCULATE( MAX( 'Table'[Posting date] ), 'Table'[Entry_Type] = "Purchase" )
    VAR lastSaleDate =
        CALCULATE( MAX( 'Table'[Posting date] ), 'Table'[Entry_Type] = "Sale" )
    VAR dateToCompare =
        IF( currentStock > 0, TODAY(), lastSaleDate )
    VAR aging =
        INT( dateToCompare - lastPurchaseDate )
    VAR inventoryFlag =
        IF( currentStock > 0, "On stock", "Out of stock" )
    RETURN
        ROW(
            "Quantity", currentStock,
            "Inventory flag", inventoryFlag,
            "Aging", aging
        )
)

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

You can create a table like

Stock summary = GENERATE(
    VALUES( 'Table'[Item_No] ),
    VAR itemNo =
        SELECTEDVALUE( 'Table'[Item_No] )
    VAR currentStock =
        CALCULATE( SUM( 'Table'[Quantity] ) )
    VAR lastPurchaseDate =
        CALCULATE( MAX( 'Table'[Posting date] ), 'Table'[Entry_Type] = "Purchase" )
    VAR lastSaleDate =
        CALCULATE( MAX( 'Table'[Posting date] ), 'Table'[Entry_Type] = "Sale" )
    VAR dateToCompare =
        IF( currentStock > 0, TODAY(), lastSaleDate )
    VAR aging =
        INT( dateToCompare - lastPurchaseDate )
    VAR inventoryFlag =
        IF( currentStock > 0, "On stock", "Out of stock" )
    RETURN
        ROW(
            "Quantity", currentStock,
            "Inventory flag", inventoryFlag,
            "Aging", aging
        )
)

Oh my god! Thank you so much! 🙂

 

Just please correct the following part of formula as the purpose is to find first PurchaseDate (MIN) and not last PurchaseDate (MAX)

VAR firstPurchaseDate =
        CALCULATE( MIN( 'Table'[Posting date] ), 'Table'[Entry_Type] = "Purchase" )

 

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!

December 2024

A Year in Review - December 2024

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