Forum Discussion
Incorrect Moving Average Date and Sum
- 8 years ago
Hi devleena,
Please try this solution to calculate moving average without adding a calendar table.
In Query Editor mode, sort the field 'DoolallySales doolally_pos_master_staging'[pos_order_date] in Ascending order. Then, add an index column.
Then, in report view, add DoolallySales doolally_pos_master_staging'[pos_order_date] into table visual, create measues like this:
TotalSales = SUM([final_total]) Rolling 7 day SUM2 = IF ( MAX ( doolally_pos_master_staging[Index] ) < 7, BLANK (), CALCULATE ( [TotalSales], FILTER ( ALL ( doolally_pos_master_staging ), doolally_pos_master_staging[Index] <= MAX ( doolally_pos_master_staging[Index] ) && doolally_pos_master_staging[Index] > MAX ( doolally_pos_master_staging[Index] ) - 7 ) ) ) Rolling 7 day Average2 = IF ( MAX ( doolally_pos_master_staging[Index] ) < 7, BLANK (), CALCULATE ( [TotalSales], FILTER ( ALL ( doolally_pos_master_staging ), doolally_pos_master_staging[Index] <= MAX ( doolally_pos_master_staging[Index] ) && doolally_pos_master_staging[Index] > MAX ( doolally_pos_master_staging[Index] ) - 7 ) ) ) / 7Best regards,
Yuliana Gu
Hmm, not sure what is going on but try posting your data as text that can be copied. Also, you might look at my Time Intelligence The Hard Way Quick Measure: https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TITHW/m-p/434008
Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
Hello Greg,
Thank you for the prompt reply .
Please find the text data below
| Date | Total Sales | 7 Day Rolling Avg |
| 13/11/15 0:00 | ₹31,650 | |
| 14/11/15 0:00 | ₹1,07,740 | |
| 15/11/15 0:00 | ₹1,38,140 | |
| 16/11/15 0:00 | ₹52,370 | |
| 17/11/15 0:00 | ₹71,570 | |
| 18/11/15 0:00 | ₹1,25,490 | |
| 19/11/15 0:00 | ₹88,890 | ₹6,15,850 |
| 20/11/15 0:00 | ₹1,50,490 | ₹7,34,690 |
| 21/11/15 0:00 | ₹1,50,520 | ₹7,77,470 |
| 23/11/15 0:00 | ₹83,270 | ₹7,22,600 |
| 24/11/15 0:00 | ₹1,15,200 | ₹7,85,430 |
| 25/11/15 0:00 | ₹89,170 | ₹8,03,030 |
| 26/11/15 0:00 | ₹76,920 | ₹7,54,460 |
| 27/11/15 0:00 | ₹2,12,510 | ₹8,78,080 |
| 28/11/15 0:00 | ₹1,51,440 | ₹8,79,030 |
| 29/11/15 0:00 | ₹1,46,350 | ₹8,74,860 |
| 30/11/15 0:00 | ₹77,640 | ₹8,69,230 |
| 01/12/15 0:00 | ₹65,970 | ₹8,20,000 |
| 02/12/15 0:00 | ₹1,24,530 | ₹8,55,360 |
| 03/12/15 0:00 | ₹87,100 | ₹8,65,540 |
| 04/12/15 0:00 | ₹1,57,820 | ₹8,10,850 |
| 05/12/15 0:00 | ₹2,05,070 | ₹8,64,480 |
| 06/12/15 0:00 | ₹1,19,550 | ₹8,37,680 |
| 07/12/15 0:00 | ₹87,170 | ₹8,47,210 |
| 08/12/15 0:00 | ₹93,570 | ₹8,74,810 |
| 09/12/15 0:00 | ₹1,50,260 | ₹9,00,540 |
| 10/12/15 0:00 | ₹1,49,450 | ₹9,62,890 |
| 11/12/15 0:00 | ₹2,36,620 | ₹10,41,690 |
| 12/12/15 0:00 | ₹1,86,540 | ₹10,23,160 |
| 13/12/15 0:00 | ₹1,37,470 | ₹10,41,080 |
Hope this helps
Thanks and Regards,
Dev