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
leniorcortivo
Advocate I
Advocate I

How to Calculate the Average Purchase Price over Multiple Purchases in Time

Hello Dear Coleagues,

 

Need your knwoledge to figure out this calculation. Please see the following transactions.

 

CodeDateOperationQuantityUnit PriceCostCumulative QuantityAverage Unit PriceAverage Unit Price + Cost
ABCD09/16/2019Purchase3U$ 156,10U$ 0,133U$ 156,10U$ 156,14
ABCD10/15/2019Purchase2U$ 164,40U$ 0,105U$ 159,42U$ 159,47
ABCD01/05/2020Purchase1U$ 171,00U$ 0,056U$ 161,35U$ 164,40
ABCD01/08/2020Sell3U$ 187,36U$ 0,113U$ 161,35U$ 161,40
ABCD01/10/2020Sell2U$ 187,50U$ 0,111U$ 161,35U$ 161,40
ABCD01/15/2020Sell1U$ 187,50U$ 0,110U$ 0,00U$ 0,00
ABCD03/09/2020Purchase1U$ 161,50U$ 0,041U$ 161,50U$ 161,54
ABCD06/30/2020Purchase1U$ 169,45U$ 0,042U$ 165,48U$ 165,52
ABCD01/13/2021Purchase3U$ 160,00U$ 0,155U$ 162,19U$ 162,24
ABCD08/09/2021Purchase2U$ 135,49U$ 0,157U$ 154,56U$ 154,62
ABCD09/01/2021Purchase4U$ 141,03U$ 0,1511U$ 149,64U$ 149,69
ABCD09/16/2021Purchase2U$ 141,24U$ 0,1513U$ 148,35U$ 148,40

 

The chalenge is to calculate correctly the last column, where over time when you hit 0 in your cumulative quantity column you must "restart" your average unit price for that point forward. When a selling operation is listed, the average unit price must not change.

 

This is a table with a single code, ABCD, but the same data source could have multiple codes. I just kept simple with one code to be more easier to understand.

 

The desired result would be a table with a single line for the code ABCD and your current (latest) Average Unit Price.

 

Thank you!

5 REPLIES 5
Syndicate_Admin
Administrator
Administrator

Good day, you have a solution for this post?, I have the same doubt.

Hello my friend. Not yet!

v-jingzhang
Community Support
Community Support

Hi @leniorcortivo 

 

Can we think that the first 7 columns (Code, Date, Operation ... Cumulative Quantity) are what you already have and the last two columns (Average Unit Price, Average Unit Price + Cost) are what you want to achieve? It is because if you already have all these 9 columns data, you just need to get data from the last line for each code, right?

 

Best Regards,
Community Support Team _ Jing

vanessafvg
Super User
Super User

so the table you have provided, is that the data that is given to you or are you asking to provide the results in that table.

 

Not sure if you asking for 2 things here?

 

create an average based on unit price cost, averaged between 0 and 0?

 

and then a single line showing the latest?   for a specific code?

 

what is the desired output in an example, can you show or is it just the last line of the table above?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




The last two columns we want to achive in the calculation. The data is on the example table just to be compared as the correct result that should be achieved in the solution.

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.