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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Rory1
New Member

SUM for same period last year , WITHOUT SAMEPERIODLASTYEAR()

Hi everyone,

 

Hope someone can help me and I hope it is possible to get this done with a measure.. should be anyway.

The idea is to calculate a sum for the previous year for max available period in the current year (months, now it's Jan-Jul). Here is my calculation for the previous period, but in this case, I get data for the total previous year instead of SUM for Jan-Jul of the previous year (the period January-July is conditional and changes depending on the available data)

 

 

 

Prev year PACKS = VAR LastYear = MAX (Media_base[Year]) - 1 RETURN CALCULATE (SUM('Media_base'[Packs]), 'Media_base'[Year]= LastYear)

 

 

 

 

Thanks!

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Rory1 ,

According to your description, I create a sample.

vkalyjmsft_0-1662603299868.png

Based on the code you provided, it did get all the sum value of previous year, as the formula does not specifically specify the month, as long as the year is last year, it meets the requirements of the formula.

vkalyjmsft_1-1662603522657.png

I modify the formula to:

Prev year PACKS =
VAR LastYear =
    MAX ( Media_base[Year] ) - 1
VAR MaxMonth =
    MAXX (
        FILTER (
            ALLSELECTED ( 'Media_base' ),
            'Media_base'[Year] = MAX ( 'Media_base'[Year] )
        ),
        'Media_base'[Month]
    )
RETURN
    CALCULATE (
        SUM ( 'Media_base'[Packs] ),
        'Media_base'[Year] = LastYear,
        'Media_base'[Month] <= MaxMonth
    )

Then get the correct result.

vkalyjmsft_2-1662603947111.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @Rory1 ,

According to your description, I create a sample.

vkalyjmsft_0-1662603299868.png

Based on the code you provided, it did get all the sum value of previous year, as the formula does not specifically specify the month, as long as the year is last year, it meets the requirements of the formula.

vkalyjmsft_1-1662603522657.png

I modify the formula to:

Prev year PACKS =
VAR LastYear =
    MAX ( Media_base[Year] ) - 1
VAR MaxMonth =
    MAXX (
        FILTER (
            ALLSELECTED ( 'Media_base' ),
            'Media_base'[Year] = MAX ( 'Media_base'[Year] )
        ),
        'Media_base'[Month]
    )
RETURN
    CALCULATE (
        SUM ( 'Media_base'[Packs] ),
        'Media_base'[Year] = LastYear,
        'Media_base'[Month] <= MaxMonth
    )

Then get the correct result.

vkalyjmsft_2-1662603947111.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

That is working as designed.  By the way, SAMEPERIODLASTYEAR is syntax sugar for DATEADD(...,-12,MONTH)

 

What you are after is YoY To Date.  That requires the combination of SAMEPERIODLASTYEAR  with another filter that indicates if the data value is "in the past"  for the previous year.  That's something you need to add as a column to your Calendar table.

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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