Forum Discussion
calculate average from table with date wise price changes
- Anonymous4 years ago
Hi nileshpca ,
Here are the steps you can follow:
1. Create measure.
table1_sum = var _summtable= SUMMARIZE('Table 2','Table 2'[all date],'Table 2'[price], "price_change", var _1=CALCULATE(SUM('Table 2'[price]),FILTER(ALL('Table 2'),'Table 2'[all date]=EARLIER('Table 2'[all date]))) var _2=CALCULATE(SUM('Table 2'[price]),FILTER(ALL('Table 2'),'Table 2'[all date]=EARLIER('Table 2'[all date])-1)) return IF( _1<> _2,MINX(FILTER(ALL('Table 2'),'Table 2'[price]=EARLIER('Table 2'[price])),[price]),BLANK()), "count",COUNTX(FILTER(ALL('Table 2'),'Table 2'[price]=EARLIER('Table 2'[price])),[all date]), "count_all",COUNTX(ALL('Table 2'),[all date]), "sum_all",SUMX(ALL('Table 2'),[price])) return DIVIDE( SUMX(_summtable,[sum_all]),SUMX(_summtable,[count_all]))2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
hi,
thanks.. was looking for a dax measure instead of power query solution since there are lot of products involved. example was given for one product to keep it simple
Hi:
I beleive if you have an additional date table (like your table 2)and run the PQ process I mentioned (and DAX sum measure after) it will be a faster solution pushing the procesing back to the query editor. Pushing back closer to source is generally best practice.
That said, here is new update to file. You just need to have your table with the four prices in it filled out with all the dates for the month. I called it "Price Table". There is DAX Calc Col.
I hope this is the solution to work for you!https://drive.google.com/file/d/1Qc6dQnkbNHkwAZeoh5eCdeI78JUDblmz/view?usp=sharing
- Whitewater1004 years ago
Solution Sage
This link has the DAX Measure in it.
New Avg Price = AVERAGE(PriceTable[New Price Fill Down])https://drive.google.com/file/d/1Qc6dQnkbNHkwAZeoh5eCdeI78JUDblmz/view?usp=sharing