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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
isa2003
Frequent Visitor

SamePeriodLastYear - MTD Issue

Hello:

I am learning how to use the time difference functions.
I have a date column in my Fact table that is connected to a Date table.
I would like to calculate YTD, QTD, MTD, Week to date sums of the Amount column.

I used the filters in the report and the calculations are correct. However, I run into issues with capturing the same using measures. For instance, today is 6/6/24. For the MTD, the calculation is correct. However, the corresponding sum for the same period from last year gives me the total June sum (not the sum from June 1-June 6).

Previous Year MTD = 
CALCULATE(
    [Amount],
    DATESMTD(SAMEPERIODLASTYEAR('DateT'[Date]))
)


Any guidance would be much appreciated. Thanks in advance.

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

HI @isa2003 ,

Perhaps you can try to manually calculate the filter range based on date function instead of nested using time intelligence functions:

Time Intelligence "The Hard Way" (TITHW)  

Previous Year MTD =
VAR currDate =
    MAX ( 'DateT'[Date] )
VAR prevDate =
    DATE ( YEAR ( currDate ) - 1, MONTH ( currDate ), DAY ( currDate ) )
RETURN
    CALCULATE (
        [Amount],
        FILTER (
            ALLSELECTED ( 'fact' ),
            [Date] >= DATE ( YEAR ( prevDate ), MONTH ( prevDate ), 1 )
                && [Date] <= prevDate
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @isa2003 ,

Perhaps you can try to manually calculate the filter range based on date function instead of nested using time intelligence functions:

Time Intelligence "The Hard Way" (TITHW)  

Previous Year MTD =
VAR currDate =
    MAX ( 'DateT'[Date] )
VAR prevDate =
    DATE ( YEAR ( currDate ) - 1, MONTH ( currDate ), DAY ( currDate ) )
RETURN
    CALCULATE (
        [Amount],
        FILTER (
            ALLSELECTED ( 'fact' ),
            [Date] >= DATE ( YEAR ( prevDate ), MONTH ( prevDate ), 1 )
                && [Date] <= prevDate
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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