Forum Discussion
Calculating previous months sales using monthly data
- Anonymous2 years ago
Hi mes0012 ,
I suggest you to create a DimDate table with continuous date in it and then try PREVIOUSMONTH.
If this reply still couldn't help you solve your issue, please share a sample file with us and show us a screenshot with the result you want.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
Here is one way to do this:
Data:
Relation:
Dax:
End result:
Here we remove YearMonth filter context and take the maximum value which is lower than current mont -> last month as context.
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/
ValtteriN, thanks for coming back on this.
I've given the above suggestion a go but i can't get it to work. I created a new table, summarised in the same way as in your suggestion above (Total Debit Balance is the original field name before i've renamed it in the visual):
However, when i build the measure i'm still getting blanks:
Any chance you can see where i've gone wrong from those screenshots?
Thanks,
Matt.
- ValtteriN2 years ago
Community Champion
Hi mes0012 ,
Now that I revisited this I realized that there isn't anything preventing you from using previousmonth like Anonymous suggested.
Here is a bit better dax (if you don't want to use PREVIOUSMONTH for one reason or another):LM =
var _cmonth = MAX('Calendar'[YearMonth])var _lmonth = CALCULATE(MAX('Table (7)'[YearMonth]),ALL('Table (7)'),'Table (7)'[YearMonth]<_cmonth)return
CALCULATE(MAX('Table (7)'[Value]),ALL('Table (7)'),'Table (7)'[YearMonth]= _lmonth)
And here is one with PREVIOUSMONTH:
LM2 = CALCULATE(MAX('Table (7)'[Value]),PREVIOUSMONTH('Calendar'[Date]))
End results: