Forum Discussion
Previous Month to Date Calculation based on current date
- 4 years ago
Hi Nanakwame
If I am reading correctly, you are quite close. I recommend creating three measures. The first is to sum the relevant values. The second to sum only the portion of the Current Month To Date. The third is to mimic the position of the Current Month To Date measure.
- Sum Value = Sum ( 'Table'[Value] )
- Total CurMthTD = CALCULATE ( [Sum Value] , DATESMTD ( 'Date'[Date] ) )
- Total LstMthTD = CALCULATE ( [Total CurMthTD] , DATEADD ('Date'[Date] , -1 , MONTH ) )
Hope this helps! 🙂 - 4 years ago
Hi Theo,
i tried the approach you provided and it seems like its calculating the 6 days for october comparing all of september. I will prefer it compare it to only 6 days in september as well and so on.
Hi Nanakwame
If I am reading correctly, you are quite close. I recommend creating three measures. The first is to sum the relevant values. The second to sum only the portion of the Current Month To Date. The third is to mimic the position of the Current Month To Date measure.
- Sum Value = Sum ( 'Table'[Value] )
- Total CurMthTD = CALCULATE ( [Sum Value] , DATESMTD ( 'Date'[Date] ) )
- Total LstMthTD = CALCULATE ( [Total CurMthTD] , DATEADD ('Date'[Date] , -1 , MONTH ) )
Hope this helps! 🙂
- tyjames052 years agoHelper I
I found this response very helpful. I've been looking for this answer for awhile now.. thank you so much. It works perfectly for me.
- Nanakwame4 years agoHelper II
Hi Theo,
i tried the approach you provided and it seems like its calculating the 6 days for october comparing all of september. I will prefer it compare it to only 6 days in september as well and so on.
- v-yingjl4 years agoCommunity Support
Hi Nanakwame ,
You can try these measures to compare:
CurrentMonthValue = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( 'Date', 'Date'[Date] >= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ) && 'Date'[Date] <= TODAY () ) )PreviousMonthValue = VAR currentmonthstart = DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ) VAR currentday = TODAY () VAR currentdiff = DATEDIFF ( currentmonthstart, currentday, DAY ) VAR previousmonthstart = EOMONTH ( TODAY (), -2 ) + 1 VAR PreviousMonthValue = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( 'Date', 'Date'[Date] >= previousmonthstart && 'Date'[Date] <= previousmonthstart + currentdiff ) ) RETURN PreviousMonthValueBest Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- JG0073 years agoRegular Visitor
I can't tell how long I've ben looking for this solution - Thanks a lot