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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Lino
Frequent Visitor

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

1 ACCEPTED SOLUTION

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

7 REPLIES 7
Anonymous
Not applicable


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!
Johanno
Responsive Resident
Responsive Resident

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.

 

Lino
Frequent Visitor

Hello @Johanno

 

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

 

First CaseFirst Case

Second CaseSecond 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

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!

Lino
Frequent Visitor


@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

Johanno
Responsive Resident
Responsive Resident

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.
Lino
Frequent Visitor


@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.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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