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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
cj_oat
Helper I
Helper I

SAMEPERIODLASTYEAR gives incorrect month for Last Year Value

Hi guys,

 

I'm trying to use SAMEPERIODLASTYEAR for MTD data, however, I found that TY month and LY month are different month (here I adjusted the formula to see what is the month that formula refering to). As you see in the screenshot for TY MTD Month is showing 2025001 which is the latest month for calendar year (the year start counting from December as 1st month) while for LY MTD Month is showing 2024012 which was only 1 month different from TY MTD Month and they are different month.

 

Not sure how should I correct the formula to see LY MTD Month as 2024001 (which is one year different from TY MTD Month)

 

TY Formula:

__TY MTD (Net Sales Value) = 
VAR LatestMonthInTable = CALCULATE(max('Sales Report'[Month]),'Sales Report'[Year]=MAX('Sales Report'[Year]),REMOVEFILTERS('Sales Report'))

VAR SelectedMonth=
    CALCULATE(MAX('Calendar Table (Date)'[Month]),'Calendar Table (Date)'[Month]<=LatestMonthinTable)

RETURN
SelectedMonth

 

LY (SAMEPERIODLASTYEAR) Formula:

__LY MTD Month = 
CALCULATE([__TY MTD (Net Sales Value)],SAMEPERIODLASTYEAR('Calendar Table (Date)'[Date]),'Sales Report'[Week Number]<=MAX('Sales Report'[Week Number]))

 

cj_oat_1-1733426914793.png

 

 

6 REPLIES 6
v-yohua-msft
Community Support
Community Support

Hi, @cj_oat 

Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster? Thank you very much for your kind cooperation!

 

Best Regards

Yongkang Hua

powerbiexpert22
Post Prodigy
Post Prodigy

Hi @cj_oat ,

 

Please follow below , please see below power bi file as reference

https://drive.google.com/file/d/1qQQ3p4KturyUUEBcWukqv6yIH6DdeXxu/view?usp=drive_link

 

1. Create calculated column 

Year = Mid(FORMAT('Sales Report'[Year - Month],"#####"),1,4)
2. Create another calculated column 
Date = DATE('Sales Report'[Year],'Sales Report'[Month Number],1)
3. Modify your measure as below 
__LY MTD (Month that formula refer to) =
FORMAT(EDATE(max('Sales Report'[Date]),-12),"YYYY0MM")

 

powerbiexpert22_0-1733492554872.png

 

cj_oat
Helper I
Helper I

Hi @powerbiexpert22 ,

 

Here I have provided link to share example of data, so basically I want to compare data between this year and last year for MTD but as screenshot below, TY value is showing 2025001 but LY turned out to show LY in 2024012 instead of 2024001...I'm not sure how SAMEPERIODLASTYEAR actually works

 

Google Drive - Example Data

 

cj_oat_0-1733471128128.png

 

Hi @cj_oat , requested access for dataset

Hi @powerbiexpert22 ,

 

Just updated the access, can you try again if you can access/download the file?

powerbiexpert22
Post Prodigy
Post Prodigy

Hi @cj_oat ,

please share sample data and expected results 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.