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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Balhemkan
Helper III
Helper III

Comparison based on slicer

Hello Team,

 

Could you please help me with the below scenario.

In x axis I am using country

I want to compare this year data with last year by default but when I select month in filter based on that month last year and this year comparison I should do.

 

Example: if I select July 2021 in “month slicer” chart should reflect from January 2020 to June 2020 because we are in mid of July.

Same way it should reflect for last year also like... January 2020 to July 2020.

 

In one vertical bar we need to show jan 2020 to June 2020

And in another vertical bar we need to show jan 2021 to June 2020 if we select july in slicer

 

Same way if we select anything in filter based on that value chart should reflect.

 

Please assist me.

 

Thanks & Regards,

Balhemkan

3 REPLIES 3
Balhemkan
Helper III
Helper III

Hi Team, 

Could you please help. 

 

amitchandak
Super User
Super User

@Balhemkan , Try like example with help from date table

 

YTD =
var _max = eomonth(maxx(allselected([Date]), 'Date'[Date]),-1)
return
if(max('Date'[Date])<=_max, calculate(Sum('order'[Qty]),DATESYTD('Date'[Date])), blank())
//or
//calculate(Sum('order'[Qty]),DATESYTD('Date'[Date]),filter('Date','Date'[Date]<=_max))
//calculate(TOTALYTD(Sum('order'[Qty]),'Date'[Date]),filter('Date','Date'[Date]<=_max))


LYTD QTY forced=
var _max = eomonth(maxx(allselected([Date]), 'Date'[Date]),-13)
return
if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
//OR
//CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
//TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

 

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak  thanks for the reply. When I do above example its not working as expected. It will be great if you help me with pbix or other solution.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.