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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
d4rren
Frequent Visitor

Change from previous year

Hi guys,

 

I am relatively new to Power Bi, and I am trying to work out the change between previous year for a dataset with years from 2017 to 2041

 

ASGSCode SexKey AgeGroupKey ERPYear Number 

125011473310020177923.5626292973
125011473310020188675.12833908559
125011473310020199869.29416907326
1250114733100202011288.4220074681
1250114733100202111780.4204141863
1250114733100202212344.0993552951
1250114733100202312739.5261897384
1250114733100202413056.1681337709
1250114733100202513607.7674308966
1250114733100202614187.0875408086
1250114733100202714730.8783805058
1250114733100202815283.5474685934
1250114733100202915827.4857965463
1250114733100203016402.0931198222
1250114733100203116971.9095157816
1250114733100203217559.8887122825
1250114733100203318122.5555377869
1250114733100203418691.4759445159
1250114733100203519265.3329322402
1250114733100203619850.5697318996
1250114733100203720448.4386043441
1250114733100203821032.7118328804
1250114733100203921547.1260050428
1250114733100204022057.0523590882
1250114733100204122565.0054992267

 

I have tried changing my year column 'ERPYear' to a date format, and attempted PREVIOUSYEAR, and SAMPLEPERIODLASTYEAR but I cant seem to get anything to work!

 

Help would be greatly appreciated - thanks!

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @d4rren 

 

You can create a Column as below.

Column = 
VAR __previousYear = 'Table'[ERPYear] - 1
VAR __previousYearNumber = 
CALCULATE(
    SUM( 'Table'[Number] ),
    ALLEXCEPT( 'Table', 'Table'[ASGSCode] ),
    'Table'[ERPYear] = __previousYear
)
RETURN 
IF( NOT ISBLANK( __previousYearNumber ), 'Table'[Number] - __previousYearNumber )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@d4rren 

Try this with a separate year table

 

diff from last year
calculate(sum(Table[Number ]),filter(Year[Year]=max(Year[Year]))) -
calculate(sum(Table[Number ]),filter(Year[Year]=max(Year[Year])-1))
or
divide(calculate(sum(Table[Number ]),filter(Year[Year]=max(Year[Year]))),
calculate(sum(Table[Number ]),filter(Year[Year]=max(Year[Year])-1)) )

 

 

Or try these with dates and date calendar

 

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Thanks @amitchandak I will try this solultion, and accept if I can get it to work

 

thank you!

Mariusz
Community Champion
Community Champion

Hi @d4rren 

 

You can create a Column as below.

Column = 
VAR __previousYear = 'Table'[ERPYear] - 1
VAR __previousYearNumber = 
CALCULATE(
    SUM( 'Table'[Number] ),
    ALLEXCEPT( 'Table', 'Table'[ASGSCode] ),
    'Table'[ERPYear] = __previousYear
)
RETURN 
IF( NOT ISBLANK( __previousYearNumber ), 'Table'[Number] - __previousYearNumber )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

@Mariusz this is exactly what I was after - so many ways of doing things in Power Bi!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors