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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
NaveenMD
Helper I
Helper I

Dynamically Referencing above rows

Material QTYRateClosing  Stock Date
1500000.2150000 11-Apr-23
00.2120000 12-Apr-23
00.296000 13-Apr-23
00.276800 14-Apr-23
00.261440 15-Apr-23
00.249152 16-Apr-23
00.239322 17-Apr-23
00.231457 18-Apr-23
00.225166 19-Apr-23
1000000.15106391 20-Apr-23
00.1590432 21-Apr-23
00.1576867 22-Apr-23
00.1565337 23-Apr-23
00.1555537 24-Apr-23

How do we calculate the closing stock based on the values in the column Material Qty 
The formula used in excel is given as =(C2+A3)*(1-B3).

 

2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @NaveenMD 
Please refer to attached sample file with the proposed solution

1.png

Closing Stock = 
VAR MinDate = MINX ( FILTER ( 'Table', 'Table'[Material QTY] > 0 ), 'Table'[Date] )
VAR T1 = FILTER ( 'Table', 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )
RETURN
    SUMX ( 
        T1,
        VAR Qty = 'Table'[Material QTY]
        VAR T2 = FILTER ( T1, 'Table'[Date] >= EARLIER ( 'Table'[Date] ) )
        VAR Rate = 
            PRODUCTX ( 
                T2, 
                IF ( 'Table'[Date] = MinDate, 1, (1 - 'Table'[Rate] ) )
            )
        RETURN
            Qty * Rate
    )

 

 

View solution in original post

I was able to identify one caviate with this formula 

Material QTYRateDateClosing Stock

00.211 April 20230
00.212 April 20230
00.213 April 20230
00.214 April 20230
00.215 April 20230
00.216 April 20230
1500000.217 April 2023120000
00.218 April 202396000
00.219 April 202376800
1000000.1520 April 2023150280
00.1521 April 2023127738
00.1522 April 2023108577
00.1523 April 202392291
00.1524 April 202378447

 

Lets say on 17th April if we add 150000 then it should be reflected as 150000 not 120000. 120000 should be the value for next day.

Excel Formula :=((1-0.2)*E2)+A3

 

Material QTYRateDateClosing StockClosing Stock 2
00.211-Apr-2300
00.212-Apr-2300
00.213-Apr-2300
00.214-Apr-2300
00.215-Apr-2300
00.216-Apr-2300
1500000.217-Apr-23120000150000
00.218-Apr-2396000120000
00.219-Apr-237680096000
1000000.1520-Apr-23150280176800
00.1521-Apr-23127738141440
00.1522-Apr-23108577113152
00.1523-Apr-239229190521.6
00.1524-Apr-237844772417.28

 

Please help

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @NaveenMD 
Please refer to attached sample file with the proposed solution

1.png

Closing Stock = 
VAR MinDate = MINX ( FILTER ( 'Table', 'Table'[Material QTY] > 0 ), 'Table'[Date] )
VAR T1 = FILTER ( 'Table', 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )
RETURN
    SUMX ( 
        T1,
        VAR Qty = 'Table'[Material QTY]
        VAR T2 = FILTER ( T1, 'Table'[Date] >= EARLIER ( 'Table'[Date] ) )
        VAR Rate = 
            PRODUCTX ( 
                T2, 
                IF ( 'Table'[Date] = MinDate, 1, (1 - 'Table'[Rate] ) )
            )
        RETURN
            Qty * Rate
    )

 

 

I was able to identify one caviate with this formula 

Material QTYRateDateClosing Stock

00.211 April 20230
00.212 April 20230
00.213 April 20230
00.214 April 20230
00.215 April 20230
00.216 April 20230
1500000.217 April 2023120000
00.218 April 202396000
00.219 April 202376800
1000000.1520 April 2023150280
00.1521 April 2023127738
00.1522 April 2023108577
00.1523 April 202392291
00.1524 April 202378447

 

Lets say on 17th April if we add 150000 then it should be reflected as 150000 not 120000. 120000 should be the value for next day.

Excel Formula :=((1-0.2)*E2)+A3

 

Material QTYRateDateClosing StockClosing Stock 2
00.211-Apr-2300
00.212-Apr-2300
00.213-Apr-2300
00.214-Apr-2300
00.215-Apr-2300
00.216-Apr-2300
1500000.217-Apr-23120000150000
00.218-Apr-2396000120000
00.219-Apr-237680096000
1000000.1520-Apr-23150280176800
00.1521-Apr-23127738141440
00.1522-Apr-23108577113152
00.1523-Apr-239229190521.6
00.1524-Apr-237844772417.28

 

Please help

@NaveenMD 

I cannot test on my laptop as I don't have access to it right now but you may try

Closing Stock =
VAR MinDate =
MINX ( FILTER ( 'Table', 'Table'[Material QTY] > 0 ), 'Table'[Date] )
VAR T1 =
FILTER ( 'Table', 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )
RETURN
SUMX (
T1,
VAR Qty = 'Table'[Material QTY]
VAR T2 =
FILTER ( T1, 'Table'[Date] >= EARLIER ( 'Table'[Date] ) )
VAR Rate =
PRODUCTX ( T2, IF ( 'Table'[Date] = MinDate, 1, ( 1 - 'Table'[Rate] ) ) )
RETURN
Qty * Rate
)

Thanks

Thank you for the solution this seems to work.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors