Forum Discussion
MTD questions
Hello all,
I have interesting question on MTD functionality and here is the question:
I have a date dimension as we know as best practice we should have date dimension and I do have one. I have a table with date and quantity sold. I wanted to create a report to show Current MTD with Prev MTD and this is what I did:
Created two measures:
CurrentMTD = CALCULATE(SUM('Cube'[Qty]),DATESMTD('Cube'[Date]))
PrevMTD = CALCULATE(SUM('Cube'[Qty]),DATEADD(DATESMTD('Cube'[Date]),-1,MONTH))
Added a filter on the graph for date and here is the result I'm getting and what I expect:
Case 1 = If date on filter is April 30th, 2014, it works fine.
CurrentMTD = 26251 (This is total of April)
PrevMTD = 6871 (This is total of March)
Case 2 = if date on filter is May 31st, 2014, I don't get correct data:
CurrentMTD = 24865 (this is total of May)
Prev MTD = 22260 (this is total of April until last transaction date of May which is May 27th) whereas for April I expect the total until April 30th and that total will be 26251
I'm wondering if this is expected behaviour or i'm doing something wrong here. Regardless, whatever date I choose on a filter, I expect correct values for current and previous MTD. I assume the same challenge will be with QTD and YTD.
Here is my sample data:
| Date | Qty | MTD | YTD | |
| 01/03/2014 | 381 | 381 | 381 | |
| 02/03/2014 | 223 | 604 | 604 | |
| 03/03/2014 | 298 | 902 | 902 | |
| 04/03/2014 | 270 | 1172 | 1172 | |
| 05/03/2014 | 243 | 1415 | 1415 | |
| 06/03/2014 | 191 | 1606 | 1606 | |
| 07/03/2014 | 288 | 1894 | 1894 | |
| 08/03/2014 | 273 | 2167 | 2167 | |
| 09/03/2014 | 201 | 2368 | 2368 | |
| 10/03/2014 | 203 | 2571 | 2571 | |
| 11/03/2014 | 205 | 2776 | 2776 | |
| 12/03/2014 | 181 | 2957 | 2957 | |
| 13/03/2014 | 283 | 3240 | 3240 | |
| 14/03/2014 | 299 | 3539 | 3539 | |
| 15/03/2014 | 248 | 3787 | 3787 | |
| 16/03/2014 | 187 | 3974 | 3974 | |
| 17/03/2014 | 212 | 4186 | 4186 | |
| 18/03/2014 | 199 | 4385 | 4385 | |
| 19/03/2014 | 187 | 4572 | 4572 | |
| 20/03/2014 | 186 | 4758 | 4758 | |
| 21/03/2014 | 236 | 4994 | 4994 | |
| 22/03/2014 | 242 | 5236 | 5236 | |
| 23/03/2014 | 144 | 5380 | 5380 | |
| 24/03/2014 | 181 | 5561 | 5561 | |
| 25/03/2014 | 196 | 5757 | 5757 | |
| 26/03/2014 | 193 | 5950 | 5950 | |
| 27/03/2014 | 188 | 6138 | 6138 | |
| 28/03/2014 | 218 | 6356 | 6356 | |
| 29/03/2014 | 215 | 6571 | 6571 | |
| 30/03/2014 | 127 | 6698 | 6698 | |
| 31/03/2014 | 173 | 6871 | 6871 | month total |
| 01/04/2014 | 194 | 194 | 7065 | |
| 02/04/2014 | 200 | 394 | 7265 | |
| 03/04/2014 | 214 | 608 | 7479 | |
| 04/04/2014 | 229 | 837 | 7708 | |
| 05/04/2014 | 263 | 1100 | 7971 | |
| 06/04/2014 | 141 | 1241 | 8112 | |
| 07/04/2014 | 178 | 1419 | 8290 | |
| 08/04/2014 | 144 | 1563 | 8434 | |
| 09/04/2014 | 144 | 1707 | 8578 | |
| 10/04/2014 | 162 | 1869 | 8740 | |
| 11/04/2014 | 206 | 2075 | 8946 | |
| 12/04/2014 | 203 | 2278 | 9149 | |
| 13/04/2014 | 949 | 3227 | 10098 | |
| 14/04/2014 | 1198 | 4425 | 11296 | |
| 15/04/2014 | 1194 | 5619 | 12490 | |
| 16/04/2014 | 1263 | 6882 | 13753 | |
| 17/04/2014 | 1309 | 8191 | 15062 | |
| 18/04/2014 | 1871 | 10062 | 16933 | |
| 19/04/2014 | 1934 | 11996 | 18867 | |
| 20/04/2014 | 402 | 12398 | 19269 | |
| 21/04/2014 | 1320 | 13718 | 20589 | |
| 22/04/2014 | 1150 | 14868 | 21739 | |
| 23/04/2014 | 1178 | 16046 | 22917 | |
| 24/04/2014 | 1312 | 17358 | 24229 | |
| 25/04/2014 | 1867 | 19225 | 26096 | |
| 26/04/2014 | 1972 | 21197 | 28068 | |
| 27/04/2014 | 1063 | 22260 | 29131 | |
| 28/04/2014 | 1318 | 23578 | 30449 | |
| 29/04/2014 | 1136 | 24714 | 31585 | |
| 30/04/2014 | 1537 | 26251 | 33122 | month total |
| 01/05/2014 | 1833 | 1833 | 34955 | |
| 02/05/2014 | 2216 | 4049 | 37171 | |
| 03/05/2014 | 1978 | 6027 | 39149 | |
| 04/05/2014 | 910 | 6937 | 40059 | |
| 05/05/2014 | 1278 | 8215 | 41337 | |
| 06/05/2014 | 1163 | 9378 | 42500 | |
| 07/05/2014 | 1154 | 10532 | 43654 | |
| 08/05/2014 | 1364 | 11896 | 45018 | |
| 09/05/2014 | 1887 | 13783 | 46905 | |
| 10/05/2014 | 1905 | 15688 | 48810 | |
| 11/05/2014 | 969 | 16657 | 49779 | |
| 12/05/2014 | 1259 | 17916 | 51038 | |
| 13/05/2014 | 1139 | 19055 | 52177 | |
| 14/05/2014 | 1104 | 20159 | 53281 | |
| 15/05/2014 | 1252 | 21411 | 54533 | |
| 16/05/2014 | 1665 | 23076 | 56198 | |
| 17/05/2014 | 1788 | 24864 | 57986 | |
| 27/05/2014 | 1 | 24865 | 57987 | month total |
15 Replies
- Greg_Deckler
Community Champion
I think you should be using the PREVIOUSMONTH function:
- bherring1979Frequent Visitor
PREVIOUSMONTH will work, but I have to ask if that date format is supported? It must be, since CurrentMTD is working.
- parry2k
Super User
Somehow my reply disappeared, seems like previous month is for full month not MTD. So in that case, do i have to have two measures, one for previousmonth and one for MTD
- leonardmurphy
Skilled Sharer
I wasn't able to recreate your original issue with the sample data given and a simple table visualization with all dates.
When I slice by 30/4/14, I see a Prev MTD result of 26251.
This means that, in my opinion, the behaviour you're expecting to see is the expected behaviour, and the fact you're not seeing it is a problem not related to the DAX formula.
I don't know what that problem is though.
Perhaps start from a fresh power bi file, just to see if you can recreate your own problem. If you can't, then see if you can find the difference between your original and your recreation. It could be something subtle to do with the relationships between tables, or the data itself. I'm really not sure.
- parry2k
Super User
if you are slicing by 30/4/2014 then current mtd will be 26251 and prev mtd (March) will be 6871 which is work fine for me as well. See case #1 in my original question.
Issue is with when you slice it 31/5/2014 (case 2 in my original question)
Thanks,