cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Resolver III

## Last month same period not computing correctly

Hiya all,

I am trying to compute the current month MTD sales and compare the same with the previous month same period. The code for both are as below :

1. MTD :

``````MTD sales =
CALCULATE(
'Measures tray'[Total Sales],DATESMTD('Date Table'[Date])
)``````

2. MTD M-1 :

``````MTD M-1 =
CALCULATE('Measures tray'[MTD sales],

)``````

Problem is that while the MTD sales are computing correctly, the previous month is computing for the whole month. Screengrab below :

I then checked the table which the DATEADD function is returning and to my surprise, instead of returning the extact same dates as current month (DATESMTD) scaled back by a month, it is actually returning the full month of Jun (Vs. 01-22 of Jul).

I dont think that is how it is supposed to work, right? or is there some other function I can work with to return the same range of dates, but with a month back?

I have gone thru some of the hacks on the web and I found that the codes they suggested are exactly like the one I have written.

Any help appreciated

1 ACCEPTED SOLUTION
Community Support

You can refer the following links to get the same period sales of last month:

Dax Same period last months

``````1-MonthSamePeriod =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER (
'Table',
AND (
[Date]
>= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 ),
[Date]
<= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) - 1 )
)
)
)``````

Same Period Last Month

``````Prev MTD =
CALCULATE (
SUM ( Sales[Sales_Amount] ),
FILTER (
ALL ( Sales[Sale_Date] ),
Sales[Sale_Date]
>= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
&& Sales[Sale_Date] <= TODAY ()
)
)``````

How to compare SAME PERIOD LAST MONTH in Power BI using DAX

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 REPLIES 5
Community Support

You can refer the following links to get the same period sales of last month:

Dax Same period last months

``````1-MonthSamePeriod =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER (
'Table',
AND (
[Date]
>= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 ),
[Date]
<= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) - 1 )
)
)
)``````

Same Period Last Month

``````Prev MTD =
CALCULATE (
SUM ( Sales[Sales_Amount] ),
FILTER (
ALL ( Sales[Sale_Date] ),
Sales[Sale_Date]
>= DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 1 )
&& Sales[Sale_Date] <= TODAY ()
)
)``````

How to compare SAME PERIOD LAST MONTH in Power BI using DAX

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Resolver III

Community Champion

@monojchakrab in order to use Time Intelligence functions you need to have a proper data table that has dates from the start to the end of the year.
If you will have this table and used the date column in it you will get the result you need.
You will probably need to create a new column that has a flag of past future and add it to the filtet pane to only show past.
Read this artilcle for full explanation:
https://www.daxpatterns.com/standard-time-related-calculations/

If you need more help you can PM me and we could do a quick zoom.

Resolver III

My dates are all from a separate date table...this is not the problem as otherwise MTD and DATESMTD would not be returning the correct table/results

We can definitely have a zoom call when convenient for you. I am in India so you can check out the time difference with your location.

Community Champion

@monojchakrab you can pm now with a link to zoom