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
sqlguru448
Helper III
Helper III

Year Over Year Measure with Year Filter as Slicer

Hello Guys,

 

I am trying to calculate Year over Year sales with Year as a slicer. I am able to achieve it when I have consecutive years but when I try to filter on year slicers with gap then it gives me incorrect result.

 

Below is the data I want to achieve when Year slicer is selected as 2016,2018.  1st table gives me correct output when no filter is applied on the Year slicer, but when the slicer is filtered on Year 2016 and 2018, I need to display the output in table 2. Please help.

 

YearCurrent Year SalesPrior Year Sales
201610000
201720001000
201835002000
  

 

Expected output for prior sales

YearCurrent Year SalesPrior Year Sales
201610000
201835001000

 

 

Thank you

 

5 REPLIES 5
sqlguru448
Helper III
Helper III

Tried to do multiple ways but if the year slicers is not selected consecutive years then the dateadd, sameperiodlast year functions are not working. Any help is really appreciated.

 

Below is the DAX which I am working on.

 
1) Count YR Slicer = CALCULATE (
COUNTROWS ( FILTERS ( 'DDM D_DATE'[YEAR_NUMBER]))|
ALLSELECTED ( 'DDM D_DATE')
)
 
2) Max Yr Slicer values = CALCULATE(topn(1|VALUES('DDM D_DATE'[YEAR_NUMBER])|'DDM D_DATE'[YEAR_NUMBER]|DESC)|ALLSELECTED('DDM D_DATE'))
 
3) Min Yr Slicer values = CALCULATE(topn(1|VALUES('DDM D_DATE'[YEAR_NUMBER]))|ALLSELECTED('DDM D_DATE'))

4) Custom Paid Amount LY =
var countdiff_2 =  If( [Count YR Slicer] = 2 && [Max Yr Slicer values] - [Min Yr Slicer values] = 2|1|0)
var MaxYrSlicer = CALCULATE(topn(1|VALUES('DDM D_DATE'[YEAR_NUMBER])|'DDM D_DATE'[YEAR_NUMBER]|DESC)|ALLSELECTED('DDM D_DATE'))
RETURN 
If(countdiff_2 <> 1| CALCULATE([Total Paid Amount]|SAMEPERIODLASTYEAR('DDM D_DATE'[CALENDAR_DATE]))|  CALCULATE([Total Paid Amount]|  DATEADD('DDM D_DATE'[CALENDAR_DATE]|-2|YEAR)))
 
kentyler
Solution Sage
Solution Sage

You need your filter to pick up the multiple months from the slicer. I found this solution in another post. 

I guess if you replace your estimation measure

EstimateCurrentMonth = calculate(sum('Sales'[Estimate]);FILTER(ALL('Sales'[MonthNumber]);[MonthNumber] = 'MonthParameter'[MonthParValue]))

with this

EstimateCurrentMonth = 
var selectedMonths = Values('MonthParameter'[MonthParValue])
return
calculate(
	sum('Sales'[Estimate])
	;FILTER(
		ALL('Sales'[MonthNumber])
		;[MonthNumber] IN selectedMonths
	)
)


 

https://community.powerbi.com/t5/Desktop/Select-multiple-values-from-slicer-for-DAX-formula/td-p/500... 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


I should have said, you need to pick up multiple years from the slicer

 

the code examples show the pattern for doing that, but you have to change the table/column names





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Yes, but this gives me only current month and current year, I don't get the prior year for the selected year 2016, 2018.


@kentyler wrote:

I should have said, you need to pick up multiple years from the slicer

 

the code examples show the pattern for doing that, but you have to change the table/column names


 

@kentyler  thank you for responding but this doesn't give me Prior year when I select different years.

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.

Top Solution Authors