Reply
Frequent Visitor
Posts: 12
Registered: ‎09-20-2017
Accepted Solution

Current Year vs Previous Year

Hello everyone

 

I have a table that contains two fields:

 

  • Date
  • Amount

 

This table contains data of 2016, 2017 and 2018.

 

My scope is creating a measure called Amount PY using DAX. For each record I want to be able to see the amount of the previous year based on the record date.

 

For example, taking the following records:

 

DateAmountAmount PY
24.03.201614 
24.03.20172314
24.03.20182623

 

I found a workaround using Power Query, but I do not like it. I would like to find a way just importing a single table and calculate the Amount PY using DAX via custom measure.

 

Is there someone who knows how to do it?

 

Thanks

Lino


Accepted Solutions
Highlighted
Regular Visitor
Posts: 38
Registered: ‎09-20-2017

Re: Current Year vs Previous Year

You must use SAMEPERIODLASTYEAR() instead of PREVIOUSUEAR(), because the last one returns ALL dates from the last year, and you need the same day shifted one year back (Using SAMEPERIODLASTYEAR()).

 

Regards!

View solution in original post


All Replies
Member
Posts: 56
Registered: ‎03-11-2018

Re: Current Year vs Previous Year

[ Edited ]

Hi, try: 

PY = CALCULATE(SUM('Table1'[Amount]);PREVIOUSYEAR(Date[Date]))

After testing I realize you first need a separate date table for this to work, e.g. New Table: Date = CALENDAR(DATE(2016;01;01);DATE(2018;12;31)). Then you can use the DAX above.

 

Frequent Visitor
Posts: 12
Registered: ‎09-20-2017

Re: Current Year vs Previous Year

Hello @Johanno

 

Thank you for the suggestion, but it does not work. 

 

2018-08-31 16_04_42-Test - Power BI Desktop.pngFirst Case

2018-08-31 16_09_17-Test - Power BI Desktop.pngSecond Case

 

In the First Case no value is showed, while in the Second Case it returns the total of the previous year basing on the year of the Date field.

 

For each day of the Date field, it should return the Amount of the same day in the previous year.

 

Regards

Lino

Member
Posts: 56
Registered: ‎03-11-2018

Re: Current Year vs Previous Year

I think you need a separate date table for this to work, I can only see one table. Then you have to create a relationship between the two date columns.
Highlighted
Regular Visitor
Posts: 38
Registered: ‎09-20-2017

Re: Current Year vs Previous Year

You must use SAMEPERIODLASTYEAR() instead of PREVIOUSUEAR(), because the last one returns ALL dates from the last year, and you need the same day shifted one year back (Using SAMEPERIODLASTYEAR()).

 

Regards!

Frequent Visitor
Posts: 12
Registered: ‎09-20-2017

Re: Current Year vs Previous Year


@Johanno wrote:
I think you need a separate date table for this to work, I can only see one table. Then you have to create a relationship between the two date columns.


Yes, this is the workaround that I already implemented, and it works, but I am loooking for a way using a single table.

Frequent Visitor
Posts: 12
Registered: ‎09-20-2017

Re: Current Year vs Previous Year


@CrisYan wrote:

You must use SAMEPERIODLASTYEAR() instead of PREVIOUSUEAR(), because the last one returns ALL dates from the last year, and you need the same day shifted one year back (Using SAMEPERIODLASTYEAR()).

 

Regards!


 

I tried more and more times this function and it never worked. Now, after your suggestion, I tried another time and now it works.

 

Thanks a lot for the suggestion.

 

Regards

Lino

Regular Visitor
Posts: 17
Registered: ‎05-04-2018

Re: Current Year vs Previous Year


Hi,

I have a list of 5 State Financial years ranging from 2013 to 2018. I am able to calculate difference between two consecutive years(2017,2018) and difference between current year 2018 with any previous year but not able to calculate difference for previous years like (2015,2017) or (2016, 2014)

The DAX functions I used here are: YTD= Total YTD([Value], (Date), “6/30”)
PYTD = Calculate([YTD], Datesbetween(Date), Date(2013,7,1), Date(2017,6,30)))

Can someone assist me here? Thanks!