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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
atult
Advocate I
Advocate I

Last Year Same Period Sales

Hi Experts,
I need to calculate the last year same period sales in a calculated measure.

Here, the 1 period = 4 weeks and hence there are 13 periods in an year.

 

Here is the table where Period format and Sales are given. Column 3(Required Measure) needs to be calculate:

 

PeriodSalesRequired Measure
2021P01100 
2021P02200 
2021P03300 
2021P04400 
2021P05500 
2022P01600100
2022P02700200
2022P03800300
2022P04900400
2022P051000500

 

Thanks in advance !

1 ACCEPTED SOLUTION

Hi,

1- create Dim Date with using the below script :

Date =
//************** Script developed by RADACAD - edition: July 2021
//************** set the variables below for your custom date table setting
var _fromYear=2021 // set the start year of the date dimension. dates start from 1st of January of this year
var _toYear=2022   // set the end year of the date dimension. dates end at 31st of December of this year
var _startOfFiscalYear=7 // set the month number that is start of the financial year. example; if fiscal year start is July, value is 7
//**************
var _today=TODAY()
return
ADDCOLUMNS(
    CALENDAR(
                DATE(_fromYear,1,1),
                DATE(_toYear,12,31)
),
"Year",YEAR([Date]),
"Month",MONTH([Date]),
"Day",DAY([Date]),
"Day of Year",DATEDIFF(DATE( YEAR([Date]), 1, 1),[Date],DAY)+1,
"Day Period Num", format( trunc( DIVIDE((DATEDIFF(DATE( YEAR([Date]), 1, 1),[Date],DAY)+1),28,0)), YEAR([Date])&"P0#")
)
* you could copy the complete Date Dim from the below site :
2- Then Create relationship between your table (it is named Sheet32 in my script) and Dim date :
MahyarTF_0-1658540233302.png

3- In the main table, create Measure for calculated the last year sales amount :

LastYearSales = CALCULATE( sum(Sheet32[Sales]), SAMEPERIODLASTYEAR('Date'[Date]) )
4- Now you could use the particular measure in your visual :
MahyarTF_1-1658540401374.png

 

Mahyartf

View solution in original post

6 REPLIES 6
MahyarTF
Memorable Member
Memorable Member

Hi,

In your Date dim, add the below column :

"Day Period Num", trunc( DIVIDE((DATEDIFF(DATE( YEAR([Date]), 1, 1),[Date],DAY)+1),28,0))
Then Manage Relationship between your table and Date table and then use SAMEPERIODLASTYEAR ( <Dates> ) Dax code in your measure
Mahyartf

Hi @MahyarTF ,
Created calculated as you suggested and mapped to the main table but didn't work. The values were only returned for the last period and that too were quite weird values.

Hi,

1- create Dim Date with using the below script :

Date =
//************** Script developed by RADACAD - edition: July 2021
//************** set the variables below for your custom date table setting
var _fromYear=2021 // set the start year of the date dimension. dates start from 1st of January of this year
var _toYear=2022   // set the end year of the date dimension. dates end at 31st of December of this year
var _startOfFiscalYear=7 // set the month number that is start of the financial year. example; if fiscal year start is July, value is 7
//**************
var _today=TODAY()
return
ADDCOLUMNS(
    CALENDAR(
                DATE(_fromYear,1,1),
                DATE(_toYear,12,31)
),
"Year",YEAR([Date]),
"Month",MONTH([Date]),
"Day",DAY([Date]),
"Day of Year",DATEDIFF(DATE( YEAR([Date]), 1, 1),[Date],DAY)+1,
"Day Period Num", format( trunc( DIVIDE((DATEDIFF(DATE( YEAR([Date]), 1, 1),[Date],DAY)+1),28,0)), YEAR([Date])&"P0#")
)
* you could copy the complete Date Dim from the below site :
2- Then Create relationship between your table (it is named Sheet32 in my script) and Dim date :
MahyarTF_0-1658540233302.png

3- In the main table, create Measure for calculated the last year sales amount :

LastYearSales = CALCULATE( sum(Sheet32[Sales]), SAMEPERIODLASTYEAR('Date'[Date]) )
4- Now you could use the particular measure in your visual :
MahyarTF_1-1658540401374.png

 

Mahyartf
Anonymous
Not applicable

@atult if you can have year column seperately,

 

then you can use this dax to get py sales.

 

Mohan1029_0-1658478484918.png

 

Accept the solution if it works for you.

Hi @Anonymous ,
It didn't work for me. Are you creating a calculated column or measure for this?

Anonymous
Not applicable

@atult it is a measure.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.