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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Measure with variable filter based on slicer

Hi All,

 

I want to calculate the sum of sales with filter on current year:

 

Current situation:

€ Sales CY = calculate([€ Sales];filter(Calender;Calender[Year]='Year variable'[CY]))
 
I would like to make the filter value variable, based on the selected value in a slicer, slicer values: CY, YTD, MTD, Current Month etc. So something like this: 
 
€ Sales = calculate([€ Sales];filter("slicer value")) 
 
How can this be done? 
 
1 REPLY 1
amitchandak
Super User
Super User

Make sure you have a powerbi date Calendar table marked as date.

https://docs.microsoft.com/en-us/dax/calendar-function-dax

https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions

 

Datesmtd, totalmtd should work for you.

https://docs.microsoft.com/en-us/dax/totalmtd-function-dax

 

 MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH'Date'[Date])))
 Last month Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))

QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD('Date'[Date]))
 Last Qtr Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(ENDOFQUARTER(dateadd('Date'[Date],-3,MONTH))))  // Use end of qtr only if required


Year  Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date Filer]))

 

These will respond to the date in the slicer . Remove endofthe ... to get till date only.

 

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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