Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
parry2k
Super User
Super User

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:

 

 

 

DateQtyMTDYTD 
01/03/2014381381381 
02/03/2014223604604 
03/03/2014298902902 
04/03/201427011721172 
05/03/201424314151415 
06/03/201419116061606 
07/03/201428818941894 
08/03/201427321672167 
09/03/201420123682368 
10/03/201420325712571 
11/03/201420527762776 
12/03/201418129572957 
13/03/201428332403240 
14/03/201429935393539 
15/03/201424837873787 
16/03/201418739743974 
17/03/201421241864186 
18/03/201419943854385 
19/03/201418745724572 
20/03/201418647584758 
21/03/201423649944994 
22/03/201424252365236 
23/03/201414453805380 
24/03/201418155615561 
25/03/201419657575757 
26/03/201419359505950 
27/03/201418861386138 
28/03/201421863566356 
29/03/201421565716571 
30/03/201412766986698 
31/03/201417368716871month total
01/04/20141941947065 
02/04/20142003947265 
03/04/20142146087479 
04/04/20142298377708 
05/04/201426311007971 
06/04/201414112418112 
07/04/201417814198290 
08/04/201414415638434 
09/04/201414417078578 
10/04/201416218698740 
11/04/201420620758946 
12/04/201420322789149 
13/04/2014949322710098 
14/04/20141198442511296 
15/04/20141194561912490 
16/04/20141263688213753 
17/04/20141309819115062 
18/04/201418711006216933 
19/04/201419341199618867 
20/04/20144021239819269 
21/04/201413201371820589 
22/04/201411501486821739 
23/04/201411781604622917 
24/04/201413121735824229 
25/04/201418671922526096 
26/04/201419722119728068 
27/04/201410632226029131 
28/04/201413182357830449 
29/04/201411362471431585 
30/04/201415372625133122month total
01/05/20141833183334955 
02/05/20142216404937171 
03/05/20141978602739149 
04/05/2014910693740059 
05/05/20141278821541337 
06/05/20141163937842500 
07/05/201411541053243654 
08/05/201413641189645018 
09/05/201418871378346905 
10/05/201419051568848810 
11/05/20149691665749779 
12/05/201412591791651038 
13/05/201411391905552177 
14/05/201411042015953281 
15/05/201412522141154533 
16/05/201416652307656198 
17/05/201417882486457986 
27/05/201412486557987month total

 

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

15 REPLIES 15
leonardmurphy
Skilled Sharer
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.

 

---
In Wisconsin? Join the Madison Power BI User Group.

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,



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Greg_Deckler
Super User
Super User

I think you should be using the PREVIOUSMONTH function:

https://support.office.com/en-US/article/PREVIOUSMONTH-Function-DAX-72fb8dda-6cd6-49e6-b9b4-8a5f6324...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

PREVIOUSMONTH will work, but I have to ask if that date format is supported? It must be, since CurrentMTD is working.

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

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

 

As per the description in previousmonth function, it will return all dates for the month and in that case MTD will not work.

 

Here is the what is says on this link https://support.office.com/en-US/article/PREVIOUSMONTH-Function-DAX-72fb8dda-6cd6-49e6-b9b4-8a5f6324...

 

This function returns all dates from the previous month, using the first date in the column used as input. For example, if the first date in the dates argument refers to June 10, 2009, this function returns all dates for the month of May, 2009.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Use PARALLELPERIOD with month as the interval and -1.

 

https://support.office.com/en-us/article/PARALLELPERIOD-Function-f38ab5a7-d88c-48a8-9eb2-dc67d5aa3f4...

 

You would use DATESMTD function as your dates input


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the reply and here is what I noticed in parallelperiod help, based on this, seems like, I cannot use it for MTD.

 

The PARALLELPERIOD function is similar to the DATEADD function except that PARALLELPERIOD always returns full periods at the given granularity level instead of the partial periods that DATEADD returns. For example, if you have a selection of dates that starts at June 10 and finishes at June 21 of the same year, and you want to shift that selection forward by one month then the PARALLELPERIOD function will return all dates from the next month (July 1 to July 31); however, if DATEADD is used instead, then the result will include only dates from July 10 to July 21.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Use DATEADD then:

https://support.office.com/en-US/article/DATEADD-Function-DAX-035e775e-6ef8-416e-816f-ebeeb826ba22


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Well assumption here is use in built function MTD/QTD/YTD, if I have to use dateadd function, not sure what is the purpose of MTD/QTD/YTD functions. 

 

I'm sure this is nothing to do with my dataset and must be a way to resolve simple MTD.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

From your previous examples, DATESMTD is working fine but you are trying to do something strange, which is DATESMTD but for the previous month, which is effectively a PARALLELPERIOD for potentially half a month or 20 days of the previous month or whatever. So, with DATEADD, you would be feeding it DATESMTD and then rewinding 30 days or whatever. That seems to be what you want to do in your latest posts and what you are trying to do unless I am severely misunderstanding something.

 

So, let's say it is the 11th of December, DATESMTD will give you 12/1/2015-12/11/2015 and then DATEADD with an interval of a month and -1 should give you 11/1/2015-11/11/2015.

 

Versus PARALLELPERIOD, which would give you 11/1/2015-11/30/2015.

 

Ultimately, I'm pretty confused here as you seem to want it both ways, in some of your posts, you want it to be one way and in some of your posts, you seem to want it to be the other way. The way that you seem to want from your original post would be to use PARALLELPERIOD, where it would give you the full date range for the previous month. That is what you seem to want from your original post, right?

 

Confused...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Yes agreed with following and that is what exactly I wanted to do.

 

So, let's say it is the 11th of December, DATESMTD will give you 12/1/2015-12/11/2015 and then DATEADD with an interval of a month and -1 should give you 11/1/2015-11/11/2015.

 

Versus PARALLELPERIOD, which would give you 11/1/2015-11/30/2015.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.



 

 

OK, but then I am confused by this statement from the original post:

 

 

"this is the total of April until last transaction date of May 27th whereas for April I expect the total until April 30th..."

 

PARALLELPERIOD will give you what is stated originally. Given DATESMTD of May 1st - May 27th, PARALLELPERIOD should return April 1st - April 30th.

 

Your DATEADD fucntion from the original post is returning April 1st - April 27th.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Here is once again:

 

If I'm slicing the data on April 30th, 2014, works great, results below.

Curr MTD is 26251 (includes April 01st to April 30th)

Prev MTD is 6871 (includes Mar 01st to Mar 31st)

 

 

If I'm slicing the data on May 31st, 2014, results are wrong and this is what I'm getting

Curr MTD is 24865(should includes May 01st - May 31st but we have data until May 27th) -> result is correct

Prev MTD is 22260 (it is only including data from April 01st - April 27th) -> result is wrong

 

I expect following reuslt in this case

Prev MTD is 26251 (April 01st - April 30th) 

 

Hope it is clear.

 

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Any other help/solution? I'm kind of stuck here not to move further my development until it is resolved.

 

Thanks!

P



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.