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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Table comparing data from a specific period with the same period of the previous year

Good

I have a Sales table, with the units sold of a product. I have the years 2022 and 2023. The client can filter for a specific period of 2023. For example 25/01/2023 to 02/02/2023. As it appears in the filter:

Filtro fechaFiltro fechaDate filter

I would like a table to appear with the month, day, you sold current year and you sold previous year.perido_actual.png

The problem is that when I add the column UdsSoldPreviousPeriod, I get the following error:error.png

It's like it won't let me calculate the units of the previous year by applying the filter segment of only the period 25/01/2023 - 02/02/2023. The measure I use to calculate the units of the previous year is as follows:

UdsVendidasPeriodoAnteriorNoWeb = 
var minfecha = MIN(Fecha[Fecha])
var minfechaN1 = DATE(YEAR(minfecha)-1,MONTH(minfecha),DAY(minfecha))
var maxfecha = MAX(Fecha[Fecha])
var maxfechaN1 = DATE(YEAR(maxfecha)-1,MONTH(maxfecha),DAY(maxfecha))
var calc = CALCULATE(SUM(Ventas[cantidad]), ALLCROSSFILTERED(Fecha), Ventas[fecha]>=minfechaN1 &&  Ventas[fecha]<=maxfechaN1)
return calc

How could I calculate it and show it in the table?

Thank you

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

Thank you so much. I have tried the SAMEPERIODLASTYEAR as you told me and it works perfectly.

Thank you!

amitchandak
Super User
Super User

@Syndicate_Admin , Make sure, you have date table joined with your table and then create a measure like

 

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

 

https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors