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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Shell
Frequent Visitor

How to create stock simulation from running total of average sales number

Hi,

I am going to make simple stock simulation of 4 products(A-D) from the data as shown below.

 

What I try to do via Power BI is 

1. make measure which is calculated average sales from past sales data

2. Get running total of average sales
3. Calculate using formula below.

     Future stock = [current stock] + [scheduled purchase number] - [ Running total of average sales]

 

I have calculated 1(average sales) by measure as below but couldn't go to 2 and 3 

 (Average_SalesNumber = CALCULATE(AVERAGE('sales_record'[sales number]),ALLEXCEPT('Date','Date'[Date]))

 

Could someone kindly let me know how to solve this??

I have made sample data and ideal result by excel as below .

 

stock

Product_codeStock
A200
B400
C350
D500

 

Average sales

Product_codeSales_Number
A50
B50
C50
D30

 

Purchase

Product_codeOrdef_VolumeArrival
A3001/08/2022
B1501/09/2022
D2030/09/2022
A501/10/2022
C4015/10/2022
A3020/11/2022
C5015/12/2022
D209/02/2023
B1508/11/2022

 

Ideal result

Shell_1-1657389026422.png

Calculation image

Prodcut_codeStatusJunJulAugSepOctNovDecJanFeb
ASell 5050505050505050
 Purchase  300 50 30  
 Stock200150400350350300280230180
BSell 5050505050505050
 Purchase   150 150   
 Stock400350300400350450400350300
CSell 5050505050505050
 Purchase    40 50  
 Stock3503002502001901401409040
DSell 3030303030303030
 Purchase   20    20
 Stock500470440430400370340310300

 

I hope your kind assisit. Thank you.

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

View solution in original post

10 REPLIES 10
Shell
Frequent Visitor

Hi, 

Thank you for your reply.

Please find the table requested.

 

Sales data

DateProdcut_codeSales_NumberPriceSales
1/01/2021A501005000
1/01/2021B20501000
1/01/2021D60704200
1/02/2021A301003000
1/03/2021C501507500
1/04/2021D1070700
1/05/2021A301003000
1/05/2021B50502500
1/05/2021B80504000
1/06/2021A10010010000
1/07/2021D20701400
1/07/2021A501005000
1/07/2021B40502000
1/08/2021C101501500
1/09/2021A501005000
1/09/2021B40502000
1/10/2021A801008000
1/10/2021B70503500
1/11/2021A401004000
1/11/2021B40502000
1/11/2021C9015013500
1/12/2021A201002000
1/12/2021B60503000

 

Purchase

* I use only arrival date as I want to know when the stock will arrive to the office, not purchase date.

Product_codeOrdef_VolumeArrivalPurcahse date
A3001/08/20221/05/2022
B1501/09/20221/08/2022
D2030/09/20221/05/2022
A501/10/20221/02/2022
C4015/10/20221/03/2022
A3020/11/20221/05/2022
C5015/12/20221/08/2022
D209/02/202317/06/2261
B1508/11/20221/02/2022

 

Please let me know if you have anything else to be needed.

 

Kind regards,

Shell

 

Ashish_Mathur
Super User
Super User

Hi,

How come there are no dates in the Sales and Purchase tables.  There should definitely be a date column in those tables.  Share as much data as is required to solve the question and show the expected result in a table format.


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

Hi Ashish,

 

Thank you for your reply.

Please find the table requested.

 

Sales data

DateProdcut_codeSales_NumberPriceSales
1/01/2021A501005000
1/01/2021B20501000
1/01/2021D60704200
1/02/2021A301003000
1/03/2021C501507500
1/04/2021D1070700
1/05/2021A301003000
1/05/2021B50502500
1/05/2021B80504000
1/06/2021A10010010000
1/07/2021D20701400
1/07/2021A501005000
1/07/2021B40502000
1/08/2021C101501500
1/09/2021A501005000
1/09/2021B40502000
1/10/2021A801008000
1/10/2021B70503500
1/11/2021A401004000
1/11/2021B40502000
1/11/2021C9015013500
1/12/2021A201002000
1/12/2021B60503000

 

Purchase

* I use only arrival date as I want to know when the stock will arrive to the office, not purchase date.

Product_codeOrdef_VolumeArrivalPurcahse date
A3001/08/20221/05/2022
B1501/09/20221/08/2022
D2030/09/20221/05/2022
A501/10/20221/02/2022
C4015/10/20221/03/2022
A3020/11/20221/05/2022
C5015/12/20221/08/2022
D209/02/202317/06/2261
B1508/11/20221/02/2022

 

Please let me know if you have anything else to be needed.

 

Kind regards,

Shell

Hi,

As requested in my previous message, please show the expected result very clearly based on the tables that you have shared.


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

Hi Ashish,

Please find the result exactly I expect as below.

 

Prodcut_codeJunJulAugSepOctNovDecJanFeb
A200150400350350300280230180
B400350300400350450400350300
C3503002502001901401409040
D500470440430400370340310300

 

And if you should be able to make graph from table above.

 

Shell_0-1657510446682.png

 

 

Kind regards,

Shell

 

 

Hi,

Sorry for asking you for more information but only with this additional information may i be able to come up with a solution.  In an MS Excel workbook, have 3 worksheets - Stock, Sales and Purchases.  In a 4th worksheet, show your expected result (with formulas intact) so that i can translate those excel formulas in the DAX language.


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

Hi Ashish,

 

Please find Excel file as requested.

https://docs.google.com/spreadsheets/d/1eSUda4Yz1hADLQ0xykgVSsuT6uYbmlSR/edit#gid=199802600

 

I add 2 sheets below other than 4 sheets you asked.

- Average_Sales : Calculation to show average sales

- Explanation : How I made the ideal result by excel

Please let me know if you have any question or data you need.

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


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

Hi Ashish,

Thank you for your great help. This is what I wanted to know.

You are welcome.


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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.