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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bignadad
Helper I
Helper I

SAMEPERIODLASTYEAR not returning correct values with fiscal year

My fiscal year is April-March

I have the Fiscal Year setup correctly in my MasterDate table.

I have a Fiscal Year Text that I use for my Slicer and a Fiscal Year Sort to sort properly.

All that is working fine.

bignadad_0-1706295041965.png

This is my measure to get my total amount

Total = CALCULATE(SUM(glentry[amount])*-1)
 
I have my Slicer filtering for FY23/24 and my total is correct
bignadad_2-1706295199958.png

 

My LY measure is not correct. Here is the measure.

LY Sales = CALCULATE(glentry[Total], SAMEPERIODLASTYEAR(MasterDate[Dates].[Date]))
 
Any idea what I'm doing wrong?
9 REPLIES 9
bignadad
Helper I
Helper I

I am pretty new to power bi and not sure how to create the pbix file with sample data. Right now all my data is set up is on dataflows. how can I get them to local sample data?

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

lbendlin
Super User
Super User

How do you know it is not correct?

@lbendlin my assumption about SAMEPERIODLASTYEAR is that the fiscal year starts in April, and traditional time intelligence functions often align with the calendar year.

SAMEPERIODLASTYEAR can be useful in this case if the MasterDate table is correctly set up & marked as a dateTable.

 

I suggest using DATESYTD or ash coding because there are other ways to achieve the same result.

What are your suggestions? Please advise

Best Regards,
Dallas.

@DallasBaba SAMEPERIODLASTYEAR is syntax suggar for DATEADD(-1,YEAR), and it works as long as your fiscal years start on the same day.  For other cases like fiscal week driven fiscal years this won't work, and you will need to compute based on the period indicators in the calendar table.

@lbendlin  Thank you for the clarity.

Best Regards,
Dallas.
DallasBaba
Super User
Super User

@bignadadThe SAMEPERIODLASTYEAR function may not work as expected because it operates based on calendar years. You can try ash coding:

LY Sales = CALCULATE(
    glentry[Total],
    DATEADD(
        VALUES(MasterDate[Dates].[Date]),
        -1,
        YEAR
    )
)

 

OR try using the DATESYTD function. 

LY Sales = CALCULATE(glentry[Total], DATESYTD(PARALLELPERIOD(MasterDate[Dates].[Date], 1, "Year")))

This measure will calculate the sales for the previous fiscal year based on the date selected in your slicer. Please note that the DATESYTD function returns the year-to-date total for the given date, so you don’t need to use the TOTALYTD function. 

 

Let me know if this works for you. @ me in replies, or I'll lose your thread!!!  
Note:
If this post is helpful, please mark it as the solution to help others find it easily. Also, if my answers contribute to a solution, show your appreciation by giving it a thumbs up
Best Regards,
Dallas.

I tried both but its still not giving the correct data

bignadad_1-1706307211140.png

I labeled the column names with your two suggestions

 

I have another page where i am manually selecting the dates and the total should be 2,636,714 for LY (April 2022 - March 2023)

bignadad_2-1706307293929.png

@bignadad can you share a pbix file with sample data? 

Best Regards,
Dallas.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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