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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Syndicate_Admin
Administrator
Administrator

Calculate stock according to purchases and sales

Hello, and thank you in advance to anyone who can help me.

I have a stock of products from the store, from a gas station.

There are purchases and sales. I need a column that gives me the total which is: 1st purchase - SALES + PURCHASES. Here is a sample excel:

DATESHOPPINGSALESSTOCK
14/6/202424 24
15/6/2024 123
17/6/2024 122
17/6/2024 220
19/6/2024 119
19/6/2024 118
19/6/2024 117
3/7/2024 116
5/7/2024 115
7/7/2024 213
10/7/2024 112
24/7/202448 60
9/8/2024 258

I need to calculate a column that the stock has so that I can then value it. The date should not matter unless it is searched as a starting point and a variable can be saved with the initial stock.

The MTDTODAY, QTDTODAY, and YTDTODAY functions are of no use to me because the calculation starts again when the period of the used formula ends

Thanks a lot

Gears

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

I have solved a similar question in the attached files.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

I have solved a similar question in the attached files.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
marcelsmaglhaes
Super User
Super User

@Syndicate_Admin 

Taking a look at the question and considering only the scenario presented, the measure to calculate the stock would be:

stock_measure =
VAR CurrentDate = MAX('Table'[DATE])
RETURN
CALCULATE(
    VAR LastStock = CALCULATE(
        [Estoque],
        FILTER(
            ALL('Table'),
            'Table'[DATE] < CurrentDate
        )
    )
    VAR CurrentShopping = SUM('Table'[SHOPPING])
    VAR CurrentSales = SUM('Table'[SALES])
    RETURN
        IF(
            ISBLANK(LastStock),
            CurrentShopping,
            LastStock + CurrentShopping - CurrentSales
        ),
    FILTER(
        ALL('Table'),
        'Table'[DATE] <= CurrentDate
    )
)

marcelsmaglhaes_0-1727204985476.png

 


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!



Hello, thanks for your help but what I need to chalk up is the STOCK column.

You need a calculated column? If yes, then the DAX is:

STOCK_COLUMN =

VAR CurrentDate = 'Table'[DATE]
RETURN
CALCULATE(
    SUM('Table'[SHOPPING]) - SUM('Table'[SALES]),
    FILTER(
        ALL('Table'),
        'Table'[DATE] <= CurrentDate
    )
)

Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!



Hello, I wanted to say that I need a new measure that calculates the column that I called Stock where I take the 24 initial products (the first purchase) and add the new purchases and subtract the sales.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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