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
sp3jossy
Frequent Visitor

Calculating Previous Year

I have a table that shows average bed_density and Survey_year (2012 - 2020).
The table is in the format
bed_density | survey_year
  2                      |  2018
  2 .5                  |  2019  
 Please  I need help finding the previous Year bed_density so that I can analyze the variance. Can you suggest a DAX to use please?
 I created a measure using  a new column -
Year relative
 as Year_Relative = survey_year  -  YEAR(TODAY()) .Then, use year relative value to calculate  bed density values:
PY_Bed density = Calculate ( [Bed_density], TableName[Year_Relative] = -1) but kept getting error in blank every time I switch year on the Year slicer.
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@sp3jossy , create a separate date/year table and use a formula like this. Join this table with your table

 

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

Refer to my Webinar

https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@sp3jossy , create a separate date/year table and use a formula like this. Join this table with your table

 

This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))

 

Refer to my Webinar

https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-Y...

Thank you !

Ashish_Mathur
Super User
Super User

Hi,

Try this approach

  1. In the table, write a calculated column formula to create a Date column: Date = 1*("1/1/"&Data[Year]).  Format this column as a Date column
  2. Create a Calendar Table with this calculated Table formula: Calendar = Calendar(min(Data[Date]),max(Data[Date]))
  3. In the Calendar Table, write this calculated column formula to extract the Year: Year = Year(Calendar[Date])
  4. Create a relationship from the Date column of the Data Table to the Date column of the Calendar Table
  5. To your visual, drag the Year column from the Calendar Table
  6. Write these measures

Bed Density = SUM(Data[bed_density])

Bed density in previous year = Calculate([Bed dinsity],previousyear(Calendar[Date]))

Variance in bed density = IFERROR([Bed Density]/[Bed density in previous year]-1,Blank())

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-qiuyu-msft
Community Support
Community Support

Hi @sp3jossy

 

You can create a measure below: 

PreYearDensity = CALCULATE(SUM('Table'[bed_density]),FILTER(ALL('Table'),'Table'[survey_year]=MAX('Table'[survey_year])-1))
 
q4.PNG
 
Best Regards,
Qiuyun Yu
Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.