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
User_790790
Regular Visitor

Calculate stock in hand from initial date

I have the following table below :- 

 

The remaining stock in hand from the end of the month (30th sep) is 30. 

 

I need to calculate stock in hand like this

01-10-2024 Stock in hand = Stock in hand end of month + Quantity Issued on 1st - QTY Sold
                                          = 30 + 5 - 2
                                          = 33

Then the remaining stock from the previous day to be added with qty issued like the below 
02-10-2024 Stock In Hand = 33 + 6 - 7 = 32

 

How can I replicate this in Power bi?

 

 

DateItem NameSalesmanQuantity IssuedQty SoldStock In Hand
01-10-24TVJohn5233
02-10-24TVJohn6732
03-10-24TVJohn13639
04-10-24TVJohn14350
05-10-24TVJohn5649
06-10-24TVJohn5747
07-10-24TVJohn3842
08-10-24TVJohn10943
09-10-24TVJohn6247
10-10-24TVJohn9650
11-10-24TVJohn6353
12-10-24TVJohn61049
3 ACCEPTED SOLUTIONS
ThxAlot
Super User
Super User

ThxAlot_0-1735364478313.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

sanalytics
Super User
Super User

@User_790790 
In case you want to achieve this result as measure instead of calculated column.
Below are the code

EOD SIH = 30
//It emans Sep's Stock in Hand
StockInhand = 
VAR _QtyIssueRT = 
CALCULATE(
    SUM( 'Table'[Quantity Issued] ),
    FILTER( ALL( 'Table'[Date] ),
    'Table'[Date] <= MAX( 'Table'[Date] )
    ) )
VAR _QtySoldRT = 
CALCULATE(
    SUM( 'Table'[Qty Sold] ),
    FILTER( ALL( 'Table'[Date] ),
    'Table'[Date] <= MAX( 'Table'[Date] )
    ) )
VAR _Result = 
[EOD SIH] + _QtyIssueRT - _QtySoldRT
RETURN
_Result

Below screenshot

sanalytics_0-1735380036920.png

Let me know if you need help for end of the mnth stock in hand.

 

Hope it helps.

 

Regards,

sanalytics



View solution in original post

pcoley
Resolver I
Resolver I

@User_790790 
Do you need a calculated column or a measure?
If it is a measure please be more precise about the model (tables and relationships available) and the existing context in the report. actually that measure correspond to a running total with the measure

stock= SUM ('Table'[Quantity Issued]) - SUM ('Table'[Qty Sold])

if all the columns are placed in the same "Table" then this measure could work:

Measure Stock in hand=
CALCULATE (
    SUM ( 'Table'[Quantity Issued] ) - SUM ( 'Table'[Qty Sold] ),
    FILTER ( ALL('Table'), 'Table'[Date] <= MAX('Table'[Date] ) )
)
​


if you need a calculated column please use this CalcColumn Dax formula: 
--> changing the "table" with your actual table name.

😁Column =
CALCULATE (
    SUM ( 'Table'[Quantity Issued] ) - SUM ( 'Table'[Qty Sold] ),
    FILTER ( ALL ( 'Table' ), 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )
)


I hope this helps, if so please accept as a solution. Kudos are welcome😁.

View solution in original post

4 REPLIES 4
pcoley
Resolver I
Resolver I

@User_790790 
Do you need a calculated column or a measure?
If it is a measure please be more precise about the model (tables and relationships available) and the existing context in the report. actually that measure correspond to a running total with the measure

stock= SUM ('Table'[Quantity Issued]) - SUM ('Table'[Qty Sold])

if all the columns are placed in the same "Table" then this measure could work:

Measure Stock in hand=
CALCULATE (
    SUM ( 'Table'[Quantity Issued] ) - SUM ( 'Table'[Qty Sold] ),
    FILTER ( ALL('Table'), 'Table'[Date] <= MAX('Table'[Date] ) )
)
​


if you need a calculated column please use this CalcColumn Dax formula: 
--> changing the "table" with your actual table name.

😁Column =
CALCULATE (
    SUM ( 'Table'[Quantity Issued] ) - SUM ( 'Table'[Qty Sold] ),
    FILTER ( ALL ( 'Table' ), 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )
)


I hope this helps, if so please accept as a solution. Kudos are welcome😁.

Thanks, i'll check it out. Sorry for the lack of clarity. I have three tables one is stock in hand from prev month, quantity issued, sales data. I would like to get the result in a new table if it's possible.

https://docs.google.com/spreadsheets/d/1mqJBUTHIwDU380uukvLYloHRgZsnS6Mz/edit?usp=sharing&ouid=10407... 

sanalytics
Super User
Super User

@User_790790 
In case you want to achieve this result as measure instead of calculated column.
Below are the code

EOD SIH = 30
//It emans Sep's Stock in Hand
StockInhand = 
VAR _QtyIssueRT = 
CALCULATE(
    SUM( 'Table'[Quantity Issued] ),
    FILTER( ALL( 'Table'[Date] ),
    'Table'[Date] <= MAX( 'Table'[Date] )
    ) )
VAR _QtySoldRT = 
CALCULATE(
    SUM( 'Table'[Qty Sold] ),
    FILTER( ALL( 'Table'[Date] ),
    'Table'[Date] <= MAX( 'Table'[Date] )
    ) )
VAR _Result = 
[EOD SIH] + _QtyIssueRT - _QtySoldRT
RETURN
_Result

Below screenshot

sanalytics_0-1735380036920.png

Let me know if you need help for end of the mnth stock in hand.

 

Hope it helps.

 

Regards,

sanalytics



ThxAlot
Super User
Super User

ThxAlot_0-1735364478313.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



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.