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
nerra
Helper II
Helper II

Ly calculated column

does anybody know how to derive a last year sales column based on the current year?

 

ly sales should correspond to the same column but different date. basically, viewing the filters (columns ) for ty net sales and then calculating ly. 

 

the formula bellow is not correct. 


Column = IF(VALUE(RELATED('filter)) =1
&& VALUE(RELATED(filter)) =1 &&
VALUE(RELATED('filter)) =1 &&
VALUE(RELATED(filter)=1 ;
CALCULATE(sum(Sales[Net Sales]);dateadd(Sales[BusinessDate];-364;DAY);0))

 

Example 

Day                  Store     Sales   Sales LY

2018-08-28     1            10       9

2017-08-29     1             9        ...   

 

 

Thanks,

Nera

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

Hi @nerra

Assume your data is like below

6.png

Create calculated columns

year = YEAR([day])

this year =
CALCULATE (
    SUM ( Sheet3[sales] ),
    FILTER (
        ALL ( Sheet3 ),
        [year] = EARLIER ( [year] )
            && [store] = EARLIER ( [store] )
    )
)

last year =
CALCULATE (
    SUM ( Sheet3[sales] ),
    FILTER (
        ALL ( Sheet3 ),
        [store] = EARLIER ( [store] )
            && [year]
                = EARLIER ( [year] ) - 1
    )
)

7.png

 

Or two measures

[Measure] is total sales of this year, [Measure 2] is total sales of last year. 

Measure =
CALCULATE (
    SUM ( Sheet3[sales] ),
    FILTER ( ALL ( Sheet3 ), [year] = MAX ( [year] ) && [store] = MAX ( [store] ) )
)

Measure 2 =
CALCULATE (
    SUM ( Sheet3[sales] ),
    FILTER (
        ALL ( Sheet3 ),
        [store] = MAX ( [store] )
            && [year]
                = MAX ( [year] ) - 1
    )
)

5.png

Best Regards

Maggie

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @nerra

Assume your data is like below

6.png

Create calculated columns

year = YEAR([day])

this year =
CALCULATE (
    SUM ( Sheet3[sales] ),
    FILTER (
        ALL ( Sheet3 ),
        [year] = EARLIER ( [year] )
            && [store] = EARLIER ( [store] )
    )
)

last year =
CALCULATE (
    SUM ( Sheet3[sales] ),
    FILTER (
        ALL ( Sheet3 ),
        [store] = EARLIER ( [store] )
            && [year]
                = EARLIER ( [year] ) - 1
    )
)

7.png

 

Or two measures

[Measure] is total sales of this year, [Measure 2] is total sales of last year. 

Measure =
CALCULATE (
    SUM ( Sheet3[sales] ),
    FILTER ( ALL ( Sheet3 ), [year] = MAX ( [year] ) && [store] = MAX ( [store] ) )
)

Measure 2 =
CALCULATE (
    SUM ( Sheet3[sales] ),
    FILTER (
        ALL ( Sheet3 ),
        [store] = MAX ( [store] )
            && [year]
                = MAX ( [year] ) - 1
    )
)

5.png

Best Regards

Maggie

Thank you Maggie! 

Indeed, it's working. I only rewrote it to use a date column -364 ! 

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.