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

View all the Fabric Data Days sessions on demand. View schedule

Reply
tbruce
Regular Visitor

Year over year comparison

I am new to PowerBI.  I am trying to add a column to a table that provides the value for the same row, but LY.

 

The data is weekly with a week number in a custom format that include the year -- YYYYWW for example, 201801 is week 1 year 2018.

POS Detail Table.JPG

I found the following formula in another forum entry... and I modified it with fixed values and it returns the right data for the first row of the table in the picture. 

 

LY POS Sales = calculate(sum('POS Detail'[POS Sales]),Filter('POS Detail','POS Detail'[Prime Item Nbr]= 8358818),Filter('POS Detail','POS Detail'[WM Week]="201833"),Filter('POS Detail','POS Detail'[Store Nbr]=390))

 

I need to know how to modify the formula so that it provides the right data for the criteria in each row.   Or is there a better way to get a % change in a table that has the data stored as below. 

 

Thanks!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

The right way to do this is create a date table, then add a date column to your data in Power Query. This old post will help with that since you only have week and year.

 

Once you've done that, the SAMEPERIODLASTYEAR() function will return the dates you need. So, say your sales is the [Total Sales] measure.

 

Sales Last Year =
CALCULATE ( 
     [Total Sales], 
     SAMEPERIODLASTYEAR ( Dates[Date] )
)

Would return sales for last year in the same context as your visual. So if your visual is showing a full year, it will be the full LY data. If it is by quarter, week, or day, it will still be the samething for last year.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Super User
Super User

The right way to do this is create a date table, then add a date column to your data in Power Query. This old post will help with that since you only have week and year.

 

Once you've done that, the SAMEPERIODLASTYEAR() function will return the dates you need. So, say your sales is the [Total Sales] measure.

 

Sales Last Year =
CALCULATE ( 
     [Total Sales], 
     SAMEPERIODLASTYEAR ( Dates[Date] )
)

Would return sales for last year in the same context as your visual. So if your visual is showing a full year, it will be the full LY data. If it is by quarter, week, or day, it will still be the samething for last year.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors