DAX Power Pivot measure – last previous value with where condition

Job ID: 32812323

Budget: $10 – $30 USD

DAX Power Pivot measure – last previous value with where condition

I am looking for a measure to calculate volume = quantity * price, where the price is the last previous price for a product.
In other words, I am looking for a DAX measure with last previous value with a "where" condition.

Take this example from the attached workbook:
I have 3 products:
- Apples
- Bananas
- Oranges
Each of these has a USD price and volume is simply quantity * price.

However, oranges can also be exchange for apples!

To sum up the value of these orange-for-apple exchange transactions with the other regular USD transactions, I first need to calculate the USD value of the oranges, and for this I need to know the last price paid for an apple, i.e. last previous price, where product = apple.

Take this example from the attached workbook:
- The last previous price paid for an apple was USD 4.21566213
- The total USD price (volume) for the 285 apples sold at that time was: 285*4.21566213= USD1201.463707
- Subsequently 1025.07924 oranges were exchanged for apples, at a rate of 0.07410448 apples per orange
- The total USD price (volume) for 1025.07924 oranges is: 1025.07924*0.07410448*4.21566213= USD320.2341908, i.e. # number of oranges * ratio oranges to apples * last previous price for an apple

Here is another example:
- The last previous price paid for an apple was USD 4.21941162
- The total USD price (volume) for 79 apples is: 79*4.21941162= USD333.333518
- Subsequently 382.74492 oranges were exchanged for apples, at a rate of 0.0741767 apples per orange
- The total USD price (volume) for 382.74492 oranges is: 382.74492 *0.0741767*4.21941162= USD119.792282

Note: I need a DAX measure that works in Power Pivot / Excel
Related categories: Power BI