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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
icdns
Post Patron
Post Patron

Same period last year using 1 table

Hi everyone, 

 

I would like to get the value same period last year using one table. I have my date and measure (value) in my table. I have no date dimension. I have this formula but it is not working 😞 

 

Can anyone help me? 

 

Previous Year Rainfall =
VAR SelectedDate = MAX(RainfallData[Date])
VAR PreviousYearDate = DATEADD(SelectedDate, -1, YEAR)
RETURN
CALCULATE(
SUM(RainfallData[Rainfall]),
FILTER(
ALL(RainfallData),
RainfallData[Date] = PreviousYearDate
)
)

 

Thank you!

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @icdns ,

 

According to your statement, I think you can try code as below to create a measure.

Previous Year Rainfall = 
VAR _CURDATE = MAX(RainfallData[Date])
RETURN
CALCULATE(
SUM(RainfallData[Rainfall]),
FILTER(
ALLSELECTED(RainfallData),
RainfallData[Date] = DATE(YEAR(_CURDATE)-1,MONTH(_CURDATE),DAY(_CURDATE))
)
)

vrzhoumsft_0-1698220689719.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @icdns ,

 

According to your statement, I think you can try code as below to create a measure.

Previous Year Rainfall = 
VAR _CURDATE = MAX(RainfallData[Date])
RETURN
CALCULATE(
SUM(RainfallData[Rainfall]),
FILTER(
ALLSELECTED(RainfallData),
RainfallData[Date] = DATE(YEAR(_CURDATE)-1,MONTH(_CURDATE),DAY(_CURDATE))
)
)

vrzhoumsft_0-1698220689719.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

littlemojopuppy
Community Champion
Community Champion

@icdns why don't you have a date table?  This would be really, really easy if you had a date table and marked it appropriately.  Then you could use time intelligence functions and specifically SAMEPERIODLASTYEAR().

Is it possible if I will not use a date table? 

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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