cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Mona01 Frequent Visitor
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

Accepted Solutions
v-yulgu-msft Super Contributor
Super Contributor

Re: calculate last year sales from multiple years pass from slicer

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
Super User
Super User

Re: calculate last year sales from multiple years pass from slicer

Hi @Mona01,

Please see the below to calculate Last Years Sales

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


Hope this Helps
Mariusz

Mona01 Frequent Visitor
Frequent Visitor

Re:Re: calculate last year sales from multiple years pass from slicer

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)

v-yulgu-msft Super Contributor
Super Contributor

Re: calculate last year sales from multiple years pass from slicer

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

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 186 members 2,028 guests
Please welcome our newest community members: