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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Mona01
Frequent Visitor

calculate last year sales from multiple years pass from slicer

Hi,

I would like to know how we can calculate last year sale when multiple years value pass from slicer.

Example: -

Slicer have values like 2011,2012,2013,2014 if we select all the years then how we can calculate the sale.

I used the above code it is working fine when there is only 1 value select in the slicer.

lastYearsalesAmount = calculate(SUM(Yearbysale[Sales]),Yearbysale[Year] in { VALUES(Yearbysale[Year])-1}, ALLEXCEPT(Yearbysale,Yearbysale[Year]))

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @Mona01 ,

 

Please refer to this measure:

lastYearsalesAmount =
CALCULATE (
    SUM ( Yearbysale[Sales] ),
    FILTER (
        ALLSELECTED ( Yearbysale ),
        Yearbysale[Year]
            = MAX ( Yearbysale[Year] ) - 1
    )
)

1.png

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

3 REPLIES 3
v-yulgu-msft
Employee
Employee

Hi @Mona01 ,

 

Please refer to this measure:

lastYearsalesAmount =
CALCULATE (
    SUM ( Yearbysale[Sales] ),
    FILTER (
        ALLSELECTED ( Yearbysale ),
        Yearbysale[Year]
            = MAX ( Yearbysale[Year] ) - 1
    )
)

1.png

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Mariusz
Community Champion
Community Champion

Hi @Mona01,

Please see the below to calculate Last Years Sales

LY Sales = 
CALCULATE(
    [Sales],
    SAMEPERIODLASTYEAR('Calendar'[Date])
)


Hope this Helps
Mariusz

Hi Mariusz,

 

I have  only a year column ,your solution is working on date . Could u suggest other option for year Column for multiple selection in slicer .

 

I have a table like that.

YearSales
2011100
2011100
2011100
201250
201250
201250
201330
201330
201330
201420
201420
201420

 

In the slicer for year i select thr years (2011,2012,2013)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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