Forum Discussion
bimagty
4 years agoFrequent Visitor
Calculate the previous month value with the same date range
Hello, I have problem with defining dax for calculating the sum of previous month, the conditions: - This month is February and the data is only available until 19 February, I have calculated th...
- 4 years ago
Hi,
Try switching the order of your fucntions:Measure = CALCULATE(SUM(Aggregation[Duration(Secs)]),datesmtd(DATEADD('Calendar'[Date],-1,MONTH)))
This will calculate MTD amounts for the previous month (using the same date range).
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/ - 4 years ago
Hi bimagty
You can try these measures. I attached a sample pbix at bottom.
This Month = VAR _endDate = MAX(Revenues[Date]) VAR _startDate = EOMONTH(_endDate,-1)+1 RETURN CALCULATE(SUM(Revenues[Revenue]),DATESBETWEEN('Calendar'[Date],_startDate,_endDate))Previous Month = VAR _maxDate = MAX(Revenues[Date]) VAR _startDate = EOMONTH(_maxDate,-2) + 1 VAR _endDate = _startDate + DAY(_maxDate) - 1 RETURN CALCULATE(SUM(Revenues[Revenue]),DATESBETWEEN('Calendar'[Date],_startDate,_endDate))Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
v-jingzhang
Community Support
4 years agoHi bimagty
You can try these measures. I attached a sample pbix at bottom.
This Month =
VAR _endDate = MAX(Revenues[Date])
VAR _startDate = EOMONTH(_endDate,-1)+1
RETURN
CALCULATE(SUM(Revenues[Revenue]),DATESBETWEEN('Calendar'[Date],_startDate,_endDate))
Previous Month =
VAR _maxDate = MAX(Revenues[Date])
VAR _startDate = EOMONTH(_maxDate,-2) + 1
VAR _endDate = _startDate + DAY(_maxDate) - 1
RETURN
CALCULATE(SUM(Revenues[Revenue]),DATESBETWEEN('Calendar'[Date],_startDate,_endDate))
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
monojchakrab
Resolver III
4 years agoGreat solution v-jingzhang - this is the best and works for me amongst all the hacks I have gone thru so far on the web.
Really helped me out of a tacky situation!