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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
dokat
Post Prodigy
Post Prodigy

YoY Calculation doesn't work with a slicer

Hi,

 

I have a data table like below where i'd like to select a date in a slicer and calculate Year over Year sales.

Slicer has 3 date options. Last Year, Last Month and Year to date and it is based on "Slicer Date" column in the table.

 

I created measure TY: = Calculate(SUM('P&L'[Values]), ALLSELECTED('P&L'[Slicer Dates]))

                              LY = CALCULATE(SUM('P&L'[Values]),DATEADD('P&L'[Slicer Dates],-1,YEAR))    or tied 
                              LY = CALCULATE(SUM('P&L'[Values]),PREVIOUSYEAR('P&L'[Slicer Dates]))
 YoY sales caculation i use below.
                             Sales Chg= ((CALCULATE(('P&L'[TY]), 'P&L'[P&L] in { "Sales"})/CALCULATE(('P&L'[LY]), 'P&L'[P&L] in { "Sales"})
 
My LY formula doesn't work and returns error calculation YoY. Can anyone help?

 

Calendar YearP&LValuesSlicer Date
12/31/2020Sales1000 
12/31/2021Sales2000Last Year
1/1/2021Sales3000 
1/1/2022Sales4000Last Month
1/31/2021Sales5000 
1/31/2022Sales2500YTD
4 REPLIES 4
mh2587
Super User
Super User

You have to put closing bracket at the end 


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



@mh2587 when i added that bracket it worked however it removed all filters in the dashboard and returning wrong values.

 

My original TY formula works the challange is when a slicer selected i can't get Last year [LY} formula to work. 

The way i am reading is when i select YTD it pulls sales for YTD 2022 but i cant get YTD 2021 and calculate YoY Chg. This issue is with [LY] formula. Please note Slicer Date column i added later on to the table based on values in Calendar Year.

 

Hope this helps clarify.

 

Thanks

mh2587
Super User
Super User

TY: = Calculate(SUM('P&L'[Values]), ALLEXCEPT('P&L'[Slicer Dates]))

change all to allexcept


Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



@mh2587  New formula returned below error message and screenshot

 

The syntax for '(' is incorrect. (DAX(Calculate(SUM('P&L'[Values]), ALLEXCEPT('P&L'(Slicer Dates])))). 

dokat_0-1644596333293.png

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors