Forum Discussion
Weight Average
- 5 years ago
This the DateAdd (-1 Year) option instead of the DATE command..... (Sorry for the change in TABLE name and columns in the version below vs. my original post.) But you only have to change the FILTER Portion to use DATEADD vs. DATE(Y)(M)(D)
1_Year_Avg_Spend = CALCULATE( SUM( 'Table'[USD Spend]) / SUM('Table'[Qty]), FILTER( 'Table', 'Table'[Document Date] > DATEADD('Table'[Document Date], -1, YEAR))) - 5 years ago
Try this....
Last_Pur_Price = CALCULATE( AVERAGE( 'Table'[Part Price]), FILTER('Table', 'Table'[Document Date] = [Last_Pur_Date]))If you had multiple sales on the same day, assuming you want the average of the two?
Hello fhill ,
So organized the data below how we would expect it to be set up.
Purchase 1 - PN-12345 Spend 500 Quantity 50 Date 10/1/2020
Purchase 2 - PN-12345 Spend 400 Quantity 40 Date 1/1/2020
Purchase 3 - PN-12345 Spend 600 Quantity 60 Date 5/1/2020
Purchase 5 - PN-12345 Spend 100 Quantity 10 Date 6/1/2019
So for the data above. The calc would only take the purchases that fall into the 365 date range from the most recent purchase (purchase 1). Thus purchase 5 would fall out of the average since its outside of that timeline. The calc for the weighted average would just be during that 365 day timeframe. Take the sum of spend and divide it by the sum of the quanitity.
Let me know if this helps
Since you will want the Last Purchase Date, and we'll use it minus 1 year in the CAL formula, start with that as it's own measure:
- Anonymous5 years agoNot applicable
Hello fhill
That first formula worked like a charm.
I'm looking for the second option you provided for the average. I'm getting a error with the formula though. Any ideas?
- fhill5 years agoResident Rockstar
This the DateAdd (-1 Year) option instead of the DATE command..... (Sorry for the change in TABLE name and columns in the version below vs. my original post.) But you only have to change the FILTER Portion to use DATEADD vs. DATE(Y)(M)(D)
1_Year_Avg_Spend = CALCULATE( SUM( 'Table'[USD Spend]) / SUM('Table'[Qty]), FILTER( 'Table', 'Table'[Document Date] > DATEADD('Table'[Document Date], -1, YEAR)))- Anonymous5 years agoNot applicable
You my friend, a genius! Thank you! What a journey haha.
One last thing... is it possible to turn that first formula you did into telling me what the price was on that date?
Orginal formula =
CALCULATE(LASTDATE(tbReceivalHistory[Document Date]),FILTER(ALLEXCEPT(tbReceivalHistory,tbReceivalHistory[Part Number (Material)]),1=1))I want this to tell me the piece price on that date it's finding.