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

Wish to create mtd,ytd from date values to be used as date slicer.

Hello, I wish to use the date column in my table to create MTD,YTD to be used in a slicer to filter the visual.

Kindly guide me on how tpo create the measures. 

What i wish to to is to be able to filter my line graph visual with a slicer that has MTD,YTD instead of filtering by selecting dates in a date slicer.

 

mtd.PNG

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@Anonymous So, you will need a disconnected table with your slicer values and then a measure like this:

Measure = 
  VAR __Selected = SELECTEDVALUE('SlicerTable'[Value])
  VAR __Year = YEAR(TODAY())
  VAR __Month = MONTH(TODAY())
  VAR __Start = IF(__Selected = "MTD", DATE(__Year,__Month,1), DATE(__Year, 1, 1))
  VAR __End = TODAY()
RETURN
  SUMX(FILTER('Table',[Date]>=__Start && [Date]<=__End), [ADSMI])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks Greg for the prompt reply, this does work and give me a MTD or YTD sum. But what i wish to do is plot the data set against date values and to be able to filter that graph by single click selecting MTD or YTD, that results in a MTD graph or YTD graph. Right now i can use the slicer with date coulumn to mauannly select the date range. but I want to be abe to single click select the Month to Date range or Year to Date range. Something like in the image below;

 

ytd.PNG

@Anonymous So like this?

 

Measure = 
  VAR __Selected = SELECTEDVALUE('SlicerTable'[Value])
  VAR __MaxDate = MAX('Table'[Date])
  VAR __Year = YEAR(__MaxDate)
  VAR __Month = MONTH(__MaxDate)
  VAR __Start = IF(__Selected = "MTD", DATE(__Year,__Month,1), DATE(__Year, 1, 1))
  VAR __End = __MaxDate
RETURN
  SUMX(FILTER('Table',[Date]>=__Start && [Date]<=__End), [ADSMI])

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hey Greg,

 

Capture1.PNGCapture2.PNG

 

As you can see I have managed to create a measure that can slicer the visual based on the selection i make on the Select Index slicer.

Firstly, as you can see from my measure, the alrnate result is Blank(), what can i do so that if nothing is selected, all the indexes are selected and the graph shows all the lines together.

 

Secondly, What i seek to achive further is to create a measure that will slice the x-axis(date) based on the selected value in the select period slicer. Like it should show date range only for 1 month back from today if i select 1 Month and so on. 

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
Top Kudoed Authors