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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Vladimir_P
New Member

SAMEPERIODLASTYEAR() function comparison

Dear Community, 

I would like to compare sales results in the same period of two consecutive years by using the SAMEPERIODLASTYEAR() function. When I do that, the presented result is not what I expected.

Instead of comparing sales results in the same period (e.g. January-June 2021. and 2020.), I'm getting the sales result for January-June 2021. and comparing it with the sales results of the complete 2020. (e.g. January-December 2020).
I'm using the function in format: IF(ISBLANK([Value]),BLANK(),CALCULATE([Value],SAMEPERIODLASTYEAR(Calendar[Date])))

SQL server is the source of data and I'm using the data by importing them to the PBI desktop. Also, I'm using the Calendar table in my model. 

I appreciate any help in advance!

Vladimir

1 ACCEPTED SOLUTION
nandic
Resident Rockstar
Resident Rockstar

Hi @Vladimir_P ,

You might try this formula:

PY amount =
VAR _year =
    MAX ( Date[Year] )
VAR _year_month =
    SELECTCOLUMNS (
        FILTER (
            SUMMARIZE ( Fact, Fact[Month], Fact[Year] ),
            Fact[Year] = _year 
        ),
        "YM", Fact[Month]
    )
RETURN
    CALCULATE (

        SUM(Fact[Amount])SAMEPERIODLASTYEAR ( Date[Date] ), _year_month )


If it doesn't work could you please share screenshot of your model and DAX that you used?
This formula is based on 1 Fact table and 1 date table.

Cheers,
Nemanja Andic

View solution in original post

2 REPLIES 2
nandic
Resident Rockstar
Resident Rockstar

Hi @Vladimir_P ,

You might try this formula:

PY amount =
VAR _year =
    MAX ( Date[Year] )
VAR _year_month =
    SELECTCOLUMNS (
        FILTER (
            SUMMARIZE ( Fact, Fact[Month], Fact[Year] ),
            Fact[Year] = _year 
        ),
        "YM", Fact[Month]
    )
RETURN
    CALCULATE (

        SUM(Fact[Amount])SAMEPERIODLASTYEAR ( Date[Date] ), _year_month )


If it doesn't work could you please share screenshot of your model and DAX that you used?
This formula is based on 1 Fact table and 1 date table.

Cheers,
Nemanja Andic

Dear @nandic ,

Thank you very much for the suggested solution. I'll try it in my model and see if it works.
Cheers!
Vladimir

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

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.

Top Solution Authors