Forum Discussion
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:
| Date | Amount | Amount PY |
| 24.03.2016 | 14 | |
| 24.03.2017 | 23 | 14 |
| 24.03.2018 | 26 | 23 |
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
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!
7 Replies
- JohannoContinued Contributor
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.
- LinoFrequent Visitor
Hello Johanno
Thank you for the suggestion, but it does not work.
First Case
Second 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
- CrisYanResolver III
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!
- AnonymousNot 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!