cancel
Showing results for
Did you mean:
Highlighted
Frequent Visitor

## Last month sales and sales of year's last month

Hi all,

I am a beginner with Power BI and I need help on this.

I need to calcule sales for last month and sales for the year of last month.

For example:

1. If today is 29/01/2019 => I should calculate:

-the sales for 12/2018 (all sales month)

AND

- the sales for all the year 2018 (from Januar to December)

2. If today is 15/03/2019 => I should calculate:

-the sales for 02/2019 (all sales month)

AND

- the sales for the year 2019 (from Januar to December)

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team

## Re: Last month sales and sales of year's last month

Hi @VEOMBOTEST,

You could refer to the measures below.

```last month_ =
VAR currentmonth =
MONTH ( MAX ( 'Data'[Date] ) )
VAR lastmonth =
IF ( currentmonth = 1, 12, currentmonth - 1 )
VAR currentyear =
YEAR ( MAX ( 'Data'[Date] ) )
VAR the_year_of_lastmonth =
IF ( currentmonth = 1, currentyear - 1, currentyear )
RETURN
CALCULATE (
SUM ( Data[Amount] ),
FILTER (
'Data',
MONTH ( 'Data'[Date] ) = lastmonth
&& YEAR ( 'Data'[Date] ) = the_year_of_lastmonth
)
)

the year of last month =
VAR currentmont =
MONTH ( MAX ( 'Data'[Date] ) )
VAR lastmonth =
IF ( currentmont = 1, 12, currentmont - 1 )
VAR currentyear =
YEAR ( MAX ( 'Data'[Date] ) )
VAR the_year_of_lastmonth =
IF ( currentmont = 1, currentyear - 1, currentyear )
RETURN
CALCULATE (
SUM ( Data[Amount] ),
FILTER ( 'Data', YEAR ( 'Data'[Date] ) = the_year_of_lastmonth )
)
```

If you want to calculated the sales of last month for each month, you may need to create another date table and then create the relationship between the tables, then create the measure like to calculate the last month value.

`last month = CALCULATE(SUM(Data[Amount]),DATEADD('Data'[Date],-1,MONTH))`

More details, you could refer to my attachment.

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
Super User

## Re: Last month sales and sales of year's last month

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

Proud to be a Datanaut!

Community Support Team

## Re: Last month sales and sales of year's last month

Hi @VEOMBOTEST,

You could refer to the measures below.

```last month_ =
VAR currentmonth =
MONTH ( MAX ( 'Data'[Date] ) )
VAR lastmonth =
IF ( currentmonth = 1, 12, currentmonth - 1 )
VAR currentyear =
YEAR ( MAX ( 'Data'[Date] ) )
VAR the_year_of_lastmonth =
IF ( currentmonth = 1, currentyear - 1, currentyear )
RETURN
CALCULATE (
SUM ( Data[Amount] ),
FILTER (
'Data',
MONTH ( 'Data'[Date] ) = lastmonth
&& YEAR ( 'Data'[Date] ) = the_year_of_lastmonth
)
)

the year of last month =
VAR currentmont =
MONTH ( MAX ( 'Data'[Date] ) )
VAR lastmonth =
IF ( currentmont = 1, 12, currentmont - 1 )
VAR currentyear =
YEAR ( MAX ( 'Data'[Date] ) )
VAR the_year_of_lastmonth =
IF ( currentmont = 1, currentyear - 1, currentyear )
RETURN
CALCULATE (
SUM ( Data[Amount] ),
FILTER ( 'Data', YEAR ( 'Data'[Date] ) = the_year_of_lastmonth )
)
```

If you want to calculated the sales of last month for each month, you may need to create another date table and then create the relationship between the tables, then create the measure like to calculate the last month value.

`last month = CALCULATE(SUM(Data[Amount]),DATEADD('Data'[Date],-1,MONTH))`

More details, you could refer to my attachment.

Best  Regards,

Cherry

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