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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
CiaraCaryl
Frequent Visitor

PYTD Function Issue

I need the PYTD function to give me just the total of sales for the same period last year as the current year period.

 

This is the formula I am using for YTD: 

YTD = TOTALYTD(SUM('Combined Table'[Quota Credit]), 'Combined Table'[QR Date].[Date])

This is the formula for PYTD:
QC PYTD = CALCULATE(TOTALYTD(SUM('Combined Table'[Quota Credit]), 'Combined Table'[QR Date].[Date]), SAMEPERIODLASTYEAR('Combined Table'[QR Date].[Date]))

For some reason, for PYTD it is giving me the total sales for the year and not just the sales for last year that match up to the current time period in this year. Any suggestions would be great!
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi,@CiaraCaryl 

1.First I have created the following table and the column names and data are the data you have given:

 

vlinyulumsft_0-1721788954741.png

2. Below are the measure I've created for your needs:

 

MEASURE = 
VAR cdate =
    CALCULATE (
        MAX ( 'Combined Table'[QR Date] ),
        FILTER (
            ALLSELECTED ( 'Combined Table' ),
            'Combined Table'[QR Date].[Year] = MAX ( 'Combined Table'[QR Date].[Year] )
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Combined Table'[Quota Credit] ),
        FILTER (
            'Combined Table',
            'Combined Table'[QR Date].[Year]
                = YEAR ( cdate ) - 1
                && 'Combined Table'[QR Date] <= EDATE ( cdate, -12 )
        )
    )

 

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1721789089805.png

 

 

vlinyulumsft_2-1721789089806.png

 

4.Here are some links that may be helpful if you have similar questions:

Solved: Need a help for Last Year YTD Data by Month select... - Microsoft Fabric Community

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

FreemanZ
Community Champion
Community Champion

hi @CiaraCaryl ,

 

TOTALYTD and SAMEPERIODLASTYEAR are time intelligence functions, to use them, you need a dedicated calendar table. Without the calendar table, try a measure like:

PYTD =
VAR _todaylastyear = EDATE(MAX('Combined Table'[QR Date]), -12)
VAR _result = 
CALCULATE(
    SUM('Combined Table'[Quota Credit]),
    FILTER(
        ALL('Combined Table'[QR Date]),
        'Combined Table'[QR Date])<_todaylastyear
            &&YEAR('Combined Table'[QR Date])) = YEAR(_todaylastyear)
    )
)
RETURN _result

View solution in original post

2 REPLIES 2
FreemanZ
Community Champion
Community Champion

hi @CiaraCaryl ,

 

TOTALYTD and SAMEPERIODLASTYEAR are time intelligence functions, to use them, you need a dedicated calendar table. Without the calendar table, try a measure like:

PYTD =
VAR _todaylastyear = EDATE(MAX('Combined Table'[QR Date]), -12)
VAR _result = 
CALCULATE(
    SUM('Combined Table'[Quota Credit]),
    FILTER(
        ALL('Combined Table'[QR Date]),
        'Combined Table'[QR Date])<_todaylastyear
            &&YEAR('Combined Table'[QR Date])) = YEAR(_todaylastyear)
    )
)
RETURN _result
Anonymous
Not applicable

Hi,@CiaraCaryl 

1.First I have created the following table and the column names and data are the data you have given:

 

vlinyulumsft_0-1721788954741.png

2. Below are the measure I've created for your needs:

 

MEASURE = 
VAR cdate =
    CALCULATE (
        MAX ( 'Combined Table'[QR Date] ),
        FILTER (
            ALLSELECTED ( 'Combined Table' ),
            'Combined Table'[QR Date].[Year] = MAX ( 'Combined Table'[QR Date].[Year] )
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Combined Table'[Quota Credit] ),
        FILTER (
            'Combined Table',
            'Combined Table'[QR Date].[Year]
                = YEAR ( cdate ) - 1
                && 'Combined Table'[QR Date] <= EDATE ( cdate, -12 )
        )
    )

 

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1721789089805.png

 

 

vlinyulumsft_2-1721789089806.png

 

4.Here are some links that may be helpful if you have similar questions:

Solved: Need a help for Last Year YTD Data by Month select... - Microsoft Fabric Community

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.