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.
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
125011473 | 3 | 100 | 2017 | 7923.5626292973 |
125011473 | 3 | 100 | 2018 | 8675.12833908559 |
125011473 | 3 | 100 | 2019 | 9869.29416907326 |
125011473 | 3 | 100 | 2020 | 11288.4220074681 |
125011473 | 3 | 100 | 2021 | 11780.4204141863 |
125011473 | 3 | 100 | 2022 | 12344.0993552951 |
125011473 | 3 | 100 | 2023 | 12739.5261897384 |
125011473 | 3 | 100 | 2024 | 13056.1681337709 |
125011473 | 3 | 100 | 2025 | 13607.7674308966 |
125011473 | 3 | 100 | 2026 | 14187.0875408086 |
125011473 | 3 | 100 | 2027 | 14730.8783805058 |
125011473 | 3 | 100 | 2028 | 15283.5474685934 |
125011473 | 3 | 100 | 2029 | 15827.4857965463 |
125011473 | 3 | 100 | 2030 | 16402.0931198222 |
125011473 | 3 | 100 | 2031 | 16971.9095157816 |
125011473 | 3 | 100 | 2032 | 17559.8887122825 |
125011473 | 3 | 100 | 2033 | 18122.5555377869 |
125011473 | 3 | 100 | 2034 | 18691.4759445159 |
125011473 | 3 | 100 | 2035 | 19265.3329322402 |
125011473 | 3 | 100 | 2036 | 19850.5697318996 |
125011473 | 3 | 100 | 2037 | 20448.4386043441 |
125011473 | 3 | 100 | 2038 | 21032.7118328804 |
125011473 | 3 | 100 | 2039 | 21547.1260050428 |
125011473 | 3 | 100 | 2040 | 22057.0523590882 |
125011473 | 3 | 100 | 2041 | 22565.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!
Solved! Go to Solution.
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 )
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/
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 )
@Mariusz this is exactly what I was after - so many ways of doing things in Power Bi!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
117 | |
107 | |
69 | |
68 | |
43 |
User | Count |
---|---|
148 | |
104 | |
102 | |
89 | |
66 |