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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
mpw
Frequent Visitor

WTD MTD YTD Slicer with Button

Hello! I am using the below formula to try to work with a slicer I created for WTD, MTD, YTD.

 

When I add the slicer to the page and the measurement, it doesn't seem to work properly with my data.

 

EL Month Conversion is the date table I am using based on my company's fiscal calendar.

 

NA Sales w LY is the table with all the sales data.

 

I would also like to include QTD.

 

Looking for a solution where the data changes with a click of a button like below.

mpw_0-1709066921639.png

 

 

WTD =
var _select=SELECTEDVALUE('EL Month Conversion'[Retailer Week])
var _select1=SELECTEDVALUE('Time Slicer'[Measure Name])
var _mtd=CALCULATE(SUM('NA Sales w LY'[TY]),FILTER(ALL('EL Month Conversion'),'EL Month Conversion'[Retailer Week]>=DATE(YEAR(_select),MONTH(_select),1)&&'EL Month Conversion'[Retailer Week]<=_select))
var _wtd=CALCULATE(SUM('NA Sales w LY'[TY]),FILTER(ALL('EL Month Conversion'),YEAR(MAX('EL Month Conversion'[Retailer Week]))= YEAR(_select)&&WEEKNUM('EL Month Conversion'[Retailer Week],1)=WEEKNUM(_select,1)))
var _ytd=CALCULATE(SUM('NA Sales w LY'[TY]),FILTER(ALL('EL Month Conversion'),'EL Month Conversion'[Retailer Week]>=DATE(YEAR(TODAY()),1,1)&&'EL Month Conversion'[Retailer Week]<=_select))
return
SWITCH(
    TRUE(),
 _select1="YTD",_ytd,
_select1="MTD",_mtd,  
    _select1="WTD",_wtd)
 
Thank you!
4 REPLIES 4
v-tangjie-msft
Community Support
Community Support

Hi @mpw ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1709086324498.png

vtangjiemsft_1-1709086356242.png

(2) We can create a measure. 

 

WTD MTD YTD QTD = 
VAR _select = SELECTEDVALUE('EL Month Conversion'[Retailer Week])
VAR _select1 = SELECTEDVALUE('Time Slicer'[Measure Name])
VAR _mtd = CALCULATE(SUM('NA Sales w LY'[TY]), FILTER(ALL('EL Month Conversion'), 'EL Month Conversion'[Retailer Week] >= DATE(YEAR(_select), MONTH(_select), 1) && 'EL Month Conversion'[Retailer Week] <= _select))
VAR _wtd = CALCULATE(SUM('NA Sales w LY'[TY]), FILTER(ALL('EL Month Conversion'), YEAR(MAX('EL Month Conversion'[Retailer Week])) = YEAR(_select) && WEEKNUM('EL Month Conversion'[Retailer Week], 1) = WEEKNUM(_select, 1)))
VAR _ytd = CALCULATE(SUM('NA Sales w LY'[TY]), FILTER(ALL('EL Month Conversion'), 'EL Month Conversion'[Retailer Week] >= DATE(YEAR(TODAY()), 1, 1) && 'EL Month Conversion'[Retailer Week] <= _select))
VAR _qtd = CALCULATE(SUM('NA Sales w LY'[TY]), FILTER(ALL('EL Month Conversion'), 'EL Month Conversion'[Retailer Week] >= STARTOFQUARTER('EL Month Conversion'[Retailer Week]) && 'EL Month Conversion'[Retailer Week] <= _select))
RETURN
SWITCH(
    TRUE(),
    _select1 = "YTD", _ytd,
    _select1 = "MTD", _mtd,
    _select1 = "WTD", _wtd,
    _select1 = "QTD", _qtd
)

 

(3) Then the result is as follows.

vtangjiemsft_2-1709086415779.png

For more details, refer: STARTOFQUARTER – DAX Guide

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Hi @v-tangjie-msft thank you for your reply! I copied the measure above but the values don't change when I click on MTD, QTD, etc. from the Time Slicer table. Is there another step I need to do for this to work?

Hi @mpw ,

 

You can create a slicer table. Please note that the slicer table has no model relationship with other tables.

Time Slicer = DATATABLE ( 
    "Measure Name", STRING, 
    {
        { "YTD"},
        { "MTD" },
        { "WTD" },
        { "QTD" }
    }
) 

Then the result is as follows.

Animation.gif

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

i followed step by step and this did not work for me. the data is still not changing.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors