Forum Discussion
Average for Month Excluding Current Month Per Product Description
- 1 year ago
Hi AartiD
If you want this to work for previous months in the current year only, you will need to identify the current month and current year in your average calculation. For this to work you will need a date table with month numbers related to your sales table. Assuming you have that, here's the solution:First, a measure to show the current month sales
Current Month Sales = CALCULATE( SUM(Sales[SalesAmount]), Sales[Month] = SELECTEDVALUE('DateTable'[Month]) )Then, the average calculation for previous months in the same year
Avg Sales Prev Months Same Year = VAR SelectedMonth = SELECTEDVALUE('DateTable'[MonthNumber]) VAR SelectedYear = SELECTEDVALUE('DateTable'[Year]) RETURN AVERAGEX( FILTER( ALL('DateTable'), 'DateTable'[Year] = SelectedYear && 'DateTable'[MonthNumber] < SelectedMonth && CALCULATE(SUM(Sales[SalesAmount])) > 0 ), CALCULATE(SUM(Sales[SalesAmount])) )I hope this helps, please give a thumbs up and mark as solved if it does, thanks!
- 1 year ago
Hi AartiD
First create monthnumber column if its not already there and try below formula.
Measure = var MaxMonthNumber=MAX(Sheet1[Custom]) Var MonthCount=MaxMonthNumber-1 var Sales=CALCULATE(SUM(Sheet1[Value]),ALLEXCEPT(Sheet1,Sheet1[Hospital Name],Sheet1[Product Desc]),Sheet1[Custom]<MaxMonthNumber) return DIVIDE(Sales,MonthCount)Custom is monthnumber, value is amount column.
Thanks.
Hi AartiD
First create monthnumber column if its not already there and try below formula.
Measure =
var MaxMonthNumber=MAX(Sheet1[Custom])
Var MonthCount=MaxMonthNumber-1
var Sales=CALCULATE(SUM(Sheet1[Value]),ALLEXCEPT(Sheet1,Sheet1[Hospital Name],Sheet1[Product Desc]),Sheet1[Custom]<MaxMonthNumber)
return
DIVIDE(Sales,MonthCount)Custom is monthnumber, value is amount column.
Thanks.