cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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.
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

Highlighted
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.

Helpful resources

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.

Power BI Helps Homeless and Trouble Youth

Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 355 members 3,045 guests
Please welcome our newest community members: