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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Sohan
Helper III
Helper III

Measure for current year and last year

I have the following measure which I would like to use to show the data for the last year and the current year. How can I achieve this without hardcoding the years? Thanks in advance!

CALCULATE(SUM(Payments[Revenue]),
FILTER(Payments, Payments[Code] = 8505))
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Sohan ;

If you want to ask for last year and this year data, it's better to use 2 measures.
This year:

this year =
CALCULATE (
    SUM ( Payments[Revenue] ),
    FILTER (
        ALL ( Payments ),
        YEAR ( [date] ) = YEAR ( MAX ( [date] ) )
            && Payments[Code] = 8505
    )
)

Last Year:

last year =
CALCULATE (
    SUM ( Payments[Revenue] ),
    FILTER (
        ALL ( Payments ),
        YEAR ( [date] )
            = YEAR ( MAX ( [date] ) ) - 1
            && Payments[Code] = 8505
    )
)

Or can you share a simple file and the result what you want output?


Best Regards,
Community Support Team _ Yalan Wu
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-yalanwu-msft
Community Support
Community Support

Hi, @Sohan ;

If you want to ask for last year and this year data, it's better to use 2 measures.
This year:

this year =
CALCULATE (
    SUM ( Payments[Revenue] ),
    FILTER (
        ALL ( Payments ),
        YEAR ( [date] ) = YEAR ( MAX ( [date] ) )
            && Payments[Code] = 8505
    )
)

Last Year:

last year =
CALCULATE (
    SUM ( Payments[Revenue] ),
    FILTER (
        ALL ( Payments ),
        YEAR ( [date] )
            = YEAR ( MAX ( [date] ) ) - 1
            && Payments[Code] = 8505
    )
)

Or can you share a simple file and the result what you want output?


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PC2790
Community Champion
Community Champion

For day on day sales from last year you can use SAMEPERIODLASTYEAR

CALCULATE([TotalSales],SAMEPERIODLASTYEAR(datesTable[Date]))

If you need particularly on yealry basis, then:

PreviousYearSales = 
var currentyear = YEAR(TODAY())
var thisyearsales = CALCULATE([TotalSales],FILTER(DatesTable, DatesTable[Year] = currentyear))

For last year, just take lastyear = YEAR(TODAY())-1

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.