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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors