Depends on your model.
In general you will need to do one of the two.
1. Generate calculated table, summarizing sales by month. Then CALCULATE(Average(CalcTable[Sales]),ALL(CalcTable)). Then subtract from each month's sales
2. Pretty much same as above, but all done within single measure. Using variable to hold summarized table and calculate.
hi @Chihiro , this is the sample file...You should provide me with sample of how your data is structured (i.e. sample file). After all, I'm not a mind reader.
ok, here you go.Sorry, but I don't use rar. If you can upload zip file I can take a look at it.
MonthlyAvg = SUM(sale[Sale])/DISTINCTCOUNT(sale[Month])
CurrentMonthSales =
var cMonth = MAX(sale[Month])
Return
CALCULATE(SUM(sale[Sale]),FILTER(sale,sale[Month]=cMonth))
Diff_CurMonth_Avg = [CurrentMonthSales]-[MonthlyAvg]
Personally, I don't like using Date Hierarchy that's auto generated by the engine.
At any rate... in this set up it's far easier to calculate average monthly by adding Month column to data. This can be done using DAX or in query stage.
Then Monthly average is calculated simply as...
Or using DIVIDE function. In this case, it shouldn't matter, as I can't imagine a case where this calculation will return DIV/0 error.Code:MonthlyAvg = SUM(sale[Sale])/DISTINCTCOUNT(sale[Month])
Then you can simply calculate the difference from given month's total.
Ex: Assuming you want the latest month's total.
Code:CurrentMonthSales = var cMonth = MAX(sale[Month]) Return CALCULATE(SUM(sale[Sale]),FILTER(sale,sale[Month]=cMonth))
Then the final result would be...
Code:Diff_CurMonth_Avg = [CurrentMonthSales]-[MonthlyAvg]
Note that you will need to change DAX measure, depending on what context you need to use it in.
Hi @ChihiroHere.
That's daily average not monthly avg. And in your initial sample you had Apr - Total. Should this be changed?
At any rate, concept is the same. You just have to change [Month] column used in calculation to [date] column.
You already have all the basis for applying the change in the previous file. I'd recommend you actually spend time to apply changes suggested to learn it yourself.
Having said that, I'll upload the file with changes applied one last time.