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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
peluca
Regular Visitor

Problem with SAMEPERIODLASTYEAR

After creating a dimdate table I tried to calculate a measure by using SAMEPERIODLASTYEAR but it does not work.

 
calculate(([Unid Actual]),SAMEPERIODLASTYEAR((DimDate[Date])))
 
1 ACCEPTED SOLUTION
vivran22
Community Champion
Community Champion

Hello @peluca,

 

What is the structure of your data table? Also, I am hoping you have created the relationship between the date of your fact table and the calendar table.

 

I have recreated the scenario with a sample data:

data table.PNG

 

And created a calendar table:

Calendar =
ADDCOLUMNS (
    CALENDAR ( MIN ( dtTable[Order Date] ), MAX ( dtTable[Order Date] ) ),
    "Year", YEAR ( [Date] ),
    "Month", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 )
)

 

And mark it as a date table. 

 

Created the relationship:

Relationship.png

 

Created measures:

 

Total Orders = SUM(dtTable[Order Quantity])

PY Orders =
CALCULATE ( [Total Orders], SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) )

 

Getting the results in visual:

 

Results.PNG

 

Regards,
Vivek

If it helps, please mark it as a solution

Kudos would be a cherry on the top 🙂

https://www.vivran.in/

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

It does work if you do it as it should be done. @vivran22 has the right solution. For the time-intel functions to work correctly, you have to have a date table that has been marked in the model as DATE TABLE and connected to the facts/dims. Nothing more.
vivran22
Community Champion
Community Champion

Hello @peluca,

 

What is the structure of your data table? Also, I am hoping you have created the relationship between the date of your fact table and the calendar table.

 

I have recreated the scenario with a sample data:

data table.PNG

 

And created a calendar table:

Calendar =
ADDCOLUMNS (
    CALENDAR ( MIN ( dtTable[Order Date] ), MAX ( dtTable[Order Date] ) ),
    "Year", YEAR ( [Date] ),
    "Month", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 )
)

 

And mark it as a date table. 

 

Created the relationship:

Relationship.png

 

Created measures:

 

Total Orders = SUM(dtTable[Order Quantity])

PY Orders =
CALCULATE ( [Total Orders], SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) )

 

Getting the results in visual:

 

Results.PNG

 

Regards,
Vivek

If it helps, please mark it as a solution

Kudos would be a cherry on the top 🙂

https://www.vivran.in/

Thanks so much for your help!!

I had an issue regarding the format of my dimdate table

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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