Forum Discussion
MTD FOR PREVIOUS PERIOD
I would like to be able to compare my MTD sales with any previous month for the same date range. Currently, I can only see MTD sales for the current month. When a previous month is chosen, the Total sales for that month is shown instead of the total sales for the same period in the current month.
So for example, if the current MTD is the 1-28th of May, I would like to be able to see the total sales for the same period for the 1st-28th of January.
Greatly appreciate it if someone can help me with this. Thank you in advance.
Hi @ganenthra94
Here is the formula modified for your case. You need also to use the month name in the visual instead of the year (from the pevious date table). However this won't work with my samp[el file as it's data has only monthly ganularity. So please try with your data.
MTD = VAR NumOfMonths = -2 VAR ReferenceDate = MAX ( 'Date'[Date] ) VAR PreviousDates = FILTER ( DATESINPERIOD ( 'PreviousDate'[Date], ReferenceDate, NumOfMonths, MONTH ), DAY ( 'PreviousDate'[Date] ) <= DAY ( ReferenceDate ) ) VAR Result = CALCULATE ( SUM ( 'Sales'[Salesl] ), REMOVEFILTERS ( 'Date' ), KEEPFILTERS ( PreviousDates ), USERELATIONSHIP ( 'PreviousDate'[Date], 'Date'[Date] ) ) RETURN Result
20 Replies
- Whitewater100
Solution Sage
Hi:
That's great if you have a separate Date Table on the "Date" field, marked as a Date Table and it has a relationship to your fact table with
your sales figures. For this example I'll call the Date Table "Dates". I'll call your fact table "Sales".
MTD Sales = CALCULATE([Total Sales], DATESMTD(Dates[Date])
PMTD = CALCULATE([Total Sales], DATEADD(FILTER(DATESMTD(Dates[Date]), DATES[Date]<TODAY()), -1,MONTH))
This will give you MTD to the day for comparison purposes.
I hope this helps!
- Whitewater100
Solution Sage
Hi:
Please see example on page 2 of the attached. (PMTD)Here there are two measures to obtain prev mtd.
Here is the link with example'
https://drive.google.com/file/d/1xS9kCnRn-y8Q-6wx5nLdZKeX9RgVURp4/view?usp=sharing
PMTD = CALCULATE([amount], DATEADD(FILTER(DATESMTD(Dates[Date]), DATES[Date]<TODAY()), -1,MONTH))Prev MTD = CALCULATE([Amount],DATEADD(FILTER(DATESMTD(Dates[Date]), Dates[Date]<TODAY()), -1,MONTH))On Jan 1 2020 =9On Jan 2 2020 =18Then look at result:(Scroll down) and the measures are blank until Feb 1 2020 =9Feb 2 2020= 18To answere your question it keeps track of the exact day for calculating the result.
Please consider marking as solution if this works for you.Thanks. - AnonymousNot applicable
Hello
Try
calculate((yourmeasure), sameperiodlastyear(date[Date]=
- AnonymousNot applicable
Does not seem to work....
- AnonymousNot applicable
Do you have a date table ?
- AnonymousNot applicable
Yes I do have a date table Anonymous
- HenriqueReis
Resolver I
Hi, how are you?
You should create a measure with this formula to see the before value you want:
Then, put the columns on a table visual and you gonna have this:
Notice I created the slicer visual too.
So, filter the visual according your preference and remove the column "VALUE" if you want:
I hope it helps you.
REGARDS!
- AnonymousNot applicable
Unfortunately it has not. But thanks anyways.
- tamerj1
Community Champion
Hi Anonymous
you can tey something like this https://community.powerbi.com/t5/DAX-Commands-and-Tips/Rolling-Cumulative-Total-Over-last-3-Year-based-on-Selected-Year/m-p/2544240#M71758
basically you need a previous date table which is just a copy of the existing date table. Then set the inactive relationship as indicated. You need to change the period of PARALLELPERIOD to 1 month
please let me know if you need any further help.
- AnonymousNot applicable
What do you mean change the period of PARALLELPERIOD to 1 month? Could not find it in the link you shared. Thanks once again.
- tamerj1
Community Champion
Hi @ganenthra94
Here is the formula modified for your case. You need also to use the month name in the visual instead of the year (from the pevious date table). However this won't work with my samp[el file as it's data has only monthly ganularity. So please try with your data.
MTD = VAR NumOfMonths = -2 VAR ReferenceDate = MAX ( 'Date'[Date] ) VAR PreviousDates = FILTER ( DATESINPERIOD ( 'PreviousDate'[Date], ReferenceDate, NumOfMonths, MONTH ), DAY ( 'PreviousDate'[Date] ) <= DAY ( ReferenceDate ) ) VAR Result = CALCULATE ( SUM ( 'Sales'[Salesl] ), REMOVEFILTERS ( 'Date' ), KEEPFILTERS ( PreviousDates ), USERELATIONSHIP ( 'PreviousDate'[Date], 'Date'[Date] ) ) RETURN Result
- tamerj1
Community Champion
Anonymous
My mistake. I mean DATESINPERIOD and to change the period to -2 month
DATESINPERIOD ( 'PreviousDate'[Date], ReferenceDate, -2, MONTH )
- AnonymousNot applicable
Hi Anonymous
Has your problem been solved ? I see that Whitewater100 tamerj1 have given a reply, is this helpful to your question? If it has been solved, then please consider Accept it as the solution to help the other members find it more quickly.
Best Regards,
Community Support Team _ Ailsa Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.